[latex3-commits] [git/LaTeX3-latex3-hyperref] newpdfstringdef: test pdfstringdef with protected chars (a0123b6)

Ulrike Fischer fischer at troubleshooting-tex.de
Thu Aug 11 02:17:36 CEST 2022


Repository : https://github.com/latex3/hyperref
On branch  : newpdfstringdef
Link       : https://github.com/latex3/hyperref/commit/a0123b6a937bb29e106680c82c6895a47393b454

>---------------------------------------------------------------

commit a0123b6a937bb29e106680c82c6895a47393b454
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Thu Aug 11 02:17:36 2022 +0200

    test pdfstringdef with protected chars


>---------------------------------------------------------------

a0123b6a937bb29e106680c82c6895a47393b454
 build.lua                          |   2 +
 new-pdfstring.sty                  | 311 +++++++++++++++++++++++++++++++++++++
 testfiles-pool/newpdfstringdef.lvt |  43 +++++
 3 files changed, 356 insertions(+)

diff --git a/build.lua b/build.lua
index f6b6d95..2644c1b 100644
--- a/build.lua
+++ b/build.lua
@@ -50,6 +50,7 @@ tdslocations = {
   "tex/latex/hyperref/hypertex.def",
   "tex/latex/hyperref/minitoc-hyper.sty",
   "tex/latex/hyperref/nameref.sty",
+  "tex/latex/hyperref/new-pdfstring.sty",
   "tex/latex/hyperref/nohyperref.sty",
   "tex/latex/hyperref/ntheorem-hyper.sty",
   "tex/latex/hyperref/pd1enc.def",
@@ -90,6 +91,7 @@ sourcefiles = {
   "*.dtx",
   "*.ins",
   "*-hyper.sty",
+  "new-pdfstring.sty",
   "bmhydoc.sty",
   "paperslides99.zip"
 }
diff --git a/new-pdfstring.sty b/new-pdfstring.sty
new file mode 100644
index 0000000..fb40e2d
--- /dev/null
+++ b/new-pdfstring.sty
@@ -0,0 +1,311 @@
+\ProvidesPackage{new-pdfstring}
+  [2022-08-10 v0.1 %
+  redefinition of pdfstringdef of hyperref]
+
+\input{putfenc.def}
+\DeclareFontFamily{PUTF}{pdf}{}%
+\DeclareFontShape{PUTF}{pdf}{m}{n}{ <-> cmr10 }{}%
+\DeclareFontSubstitution{PUTF}{pdf}{m}{n}
+
+%
+\def\newpdfstringdef#1#2{%
+  \begingroup
+    \escapechar`\\%
+    \edef\0{\string\0}%
+    \edef\1{\string\1}%
+    \edef\2{\string\2}%
+    \edef\3{\string\3}%
+    \edef\8{\string\8}%
+    \edef\9{\string\9}%
+    \fontencoding{PUTF}%
+    \HyPsd at UTFviii% ??????? only unichar
+    \let\utf at viii@undeferr\HyPsd at utf@viii at undeferr % needed?
+    \enc at update
+    \@inmathwarn\pdfstringdef
+    \let\@inmathwarn\HyPsd at inmathwarn
+    \let\add at accent\HyPsd at add@accent
+    \let\{\textbraceleft
+    \let\}\textbraceright
+    \let\\\textbackslash
+    \let\#\textnumbersign
+    \let\$\textdollar
+    \let\%\textpercent
+    \let\&\textampersand
+    \let\_\textunderscore
+    \let\P\textparagraph
+    \let\ldots\textellipsis
+    \let\dots\textellipsis
+    \ltx at IfUndefined{textEncodingNoboundary}%
+      {}{\let\noboundary\textEncodingNoboundary}%
+    \def\\{\pdfstringdefWarn\\}%
+    \def\newline{\pdfstringdefWarn\newline}%
+    \def\TeX{TeX}%
+    \def\LaTeX{La\TeX}%
+    \def\LaTeXe{\LaTeX2ε}%
+    \def\eTeX{ε-\TeX}%
+    \def\SliTeX{Sli\TeX}%
+    \def\MF{Metafont}%
+    \def\MP{Metapost}%
+    \let\fontencoding\@gobble
+    \let\fontfamily\@gobble
+    \let\fontseries\@gobble
+    \let\fontshape\@gobble
+    \let\fontsize\@gobbletwo
+    \let\selectfont\@empty
+    \let\usefont\@gobblefour
+    \let\emph\@firstofone
+    \let\textnormal\@firstofone
+    \let\textrm\@firstofone
+    \let\textsf\@firstofone
+    \let\texttt\@firstofone
+    \let\textbf\@firstofone
+    \let\textmd\@firstofone
+    \let\textit\@firstofone
+    \let\textsc\@firstofone
+    \let\textsl\@firstofone
+    \let\textup\@firstofone
+    \let\normalfont\@empty
+    \let\rmfamily\@empty
+    \let\sffamily\@empty
+    \let\ttfamily\@empty
+    \let\bfseries\@empty
+    \let\mdseries\@empty
+    \let\itshape\@empty
+    \let\scshape\@empty
+    \let\slshape\@empty
+    \let\upshape\@empty
+    \let\em\@empty
+    \let\rm\@empty
+    \let\Huge\@empty
+    \let\LARGE\@empty
+    \let\Large\@empty
+    \let\footnotesize\@empty
+    \let\huge\@empty
+    \let\large\@empty
+    \let\normalsize\@empty
+    \let\scriptsize\@empty
+    \let\small\@empty
+    \let\tiny\@empty
+    \let\mathversion\@gobble
+    \let\phantom\@gobble
+    \let\vphantom\@gobble
+    \let\hphantom\@gobble
+    \let\ding\HyPsd at ding
+    \let\Cube\HyPsd at DieFace
+    \def\begin##1{\csname##1\endcsname}%
+    \def\end##1{\csname end##1\endcsname}%
+    \def\textcolor##1##{\@secondoftwo}%
+    \def\MakeUppercase{\MakeUppercaseUnsupportedInPdfStrings}%
+    \def\MakeLowercase{\MakeLowercaseUnsupportedInPdfStrings}%
+    \ifHy at psdextra
+        \csname psdmapshortnames\endcsname
+        \csname psdaliasnames\endcsname
+    \fi
+    \let\foreignlanguage\@secondoftwo
+    \let\textlatin\@firstofone
+    \ltx at IfUndefined{language at group}{}{%
+      \let\bbl at info\@gobble
+      \csname HyPsd at babel@\language at group\endcsname
+    }%
+    \let\@safe at activestrue\relax
+    \let\@safe at activesfalse\relax
+    \let\cyr\relax
+    \let\glqq\textglqq
+    \let\grqq\textgrqq
+    \let\glq\textglq
+    \let\grq\textgrq
+    \let\flqq\textflqq
+    \let\frqq\textfrqq
+    \let\flq\textflq
+    \let\frq\textfrq
+    \let\if at mid@expandable\@firstoftwo
+    \HyPsd at AMSclassfix
+    \let\hspace\HyPsd at hspace
+    \let\label\@gobble
+    \let\index\@gobble
+    \let\glossary\@gobble
+    \let\href\HyPsd at href
+    \let\@mkboth\@gobbletwo
+    \let\ref\HyPsd at ref
+    \let\pageref\HyPsd at pageref
+    \let\nameref\HyPsd at nameref
+    \let\autoref\HyPsd at autoref
+    \let\leavevmode\@empty
+    \let\mbox\@empty
+    \def\halign{\pdfstringdefWarn\halign\@gobble}%
+    \let\ignorespaces\HyPsd at ignorespaces
+    \let\Hy at SectionAnchorHref\@gobble
+    \let\ensuremath\@firstofone
+    \Hy at pdfstringtrue
+    \pdfstringdefPreHook
+    \HyPsd at LetUnexpandableSpace\space
+    \HyPsd at LetUnexpandableSpace\ %
+    \HyPsd at LetUnexpandableSpace~%
+    \HyPsd at LetUnexpandableSpace\nobreakspace
+    \ltx at IfUndefined{@xspace}{%
+      \let\xspace\HyPsd at ITALCORR
+    }{%
+      \let\xspace\HyPsd at XSPACE
+    }%
+    \let\/\HyPsd at ITALCORR
+    \let\bgroup\/%
+    \let\egroup\/%
+    \let\discretionary\@gobbletwo
+    \def\@ifnextchar{\HyPsd at ifnextchar\@ifnextchar}%
+    \def\kernel at ifnextchar{\HyPsd at ifnextchar\kernel at ifnextchar}%
+    \def\new at ifnextchar{\HyPsd at ifnextchar\new at ifnextchar}%
+    \let\@protected at testopt\HyPsd at protected@testopt
+    \let\@protected at testopt@xargs\HyPsd at protected@testopt
+    \begingroup
+      \let\GenericError\@gobblefour
+      \let\GenericWarning\@gobbletwo
+      \let\GenericInfo\@gobbletwo
+      \ifx\nofrenchguillemets\@undefined
+      \else
+        \nofrenchguillemets
+      \fi
+      \let\Hy at temp\xdef
+      \let\def\HyPsd at DefCommand
+      \let\gdef\HyPsd at DefCommand
+      \let\edef\HyPsd at DefCommand
+      \let\xdef\HyPsd at DefCommand
+      \let\futurelet\HyPsd at LetCommand
+      \let\let\HyPsd at LetCommand
+      \Hy at temp#1{#2}%
+    \endgroup
+    \ifx#1\@empty
+    \else
+      \HyPsd at ProtectSpaces#1%
+      \let\HyPsd at String\@empty
+      \expandafter\HyPsd at RemoveBraces\expandafter{#1|}%
+      \global\let#1\HyPsd at String
+      \let\HyPsd at SPACEOPTI\relax
+      {%
+         \let\HyPsd at String\@empty
+         \expandafter\HyPsd at CheckCatcodes#1\HyPsd at End
+         \global\let#1\HyPsd at String
+      }%
+      \expandafter\HyPsd at RemoveMask\expandafter
+        |\expandafter\@empty#1\HyPsd at End#1%
+      \expandafter
+      \HyPsd at Subst\expandafter{\HyPsd at GLYPHERR}{\relax}#1%
+      \let\HyPsd at String\@empty
+      \expandafter\HyPsd at GlyphProcess#1\relax\@empty
+      \global\let#1\HyPsd at String
+      \HyPsd at StringSubst{\\}{\textbackslash}#1%
+      \expandafter\HyPsd at StringSubst\csname 80\040\endcsname
+          \HyPsd at SPACEOPTI#1%
+      \edef\Hy at temp@A{\HyPsd at SPACEOPTI\HyPsd at SPACEOPTI\80\273}%
+      \expandafter\HyPsd at Subst\expandafter{\Hy at temp@A}%
+          {\HyPsd at SPACEOPTI»}#1%
+      \HyPsd at StringSubst{\)}{)}#1%
+      \let\HyPsd at empty\relax
+      \expandafter\HyPsd at StringSubst\csname 80\051\endcsname
+          {\HyPsd at empty)}#1%
+      \expandafter\HyPsd at Subst\expandafter{\/}\HyPsd at empty#1%
+      \ltx at IfUndefined{@xspace}{%
+      }{%
+        \let\HyPsd at xspace\relax
+        \expandafter\HyPsd at Subst\expandafter
+          {\HyPsd at XSPACE}\HyPsd at xspace#1%
+        \let\HyPsd at xspace\HyPsd at doxspace
+      }%
+      \xdef#1{#1\HyPsd at empty}%
+      \HyPsd at Subst{---}\textemdash#1%
+      \HyPsd at Subst{--}\textendash#1%
+      \HyPsd at Subst{!`}\textexclamdown#1%
+      \HyPsd at Subst{?`}\textquestiondown#1%
+      \let\HyPsd at empty\@empty
+      \HyPsd at StringSubst\(\textparenleft#1%
+      \HyPsd at Subst(\textparenleft#1%
+      \edef\HyPsd at SPACEOPTI{ }%
+      \xdef#1{#1\@empty}%
+    \fi
+  \endgroup
+  \begingroup
+    \HyPsd at ConvertToUnicode#1%
+    \pdfstringdefPostHook#1%
+  \endgroup
+}
+
+
+\ExplSyntaxOn
+\cs_generate_variant:Nn\str_gset_convert:Nnnn{NVnn}
+
+\def\HyPsd at ConvertToUnicode#1
+  {
+    \ifHy at unicode
+    \str_gset_convert:NVnn #1 #1
+        { default }
+        {utf16/string}
+    \else
+    \str_gset_convert:NVnn #1 #1
+        { default }
+        {utf8/string}
+    \fi
+  }
+
+\ExplSyntaxOff
+\def\HyPsd at expand@utfvii{\ERROR}
+\def\HyPsd at UTFviii{\let\unichar\HyPsd at unichar} %?
+
+\def\HyPsd at DieFace#1{%
+  \ifnum#1<1 %
+      \HyPsd at UnicodeReplacementCharacter
+  \else
+      \ifcase#1
+         \or ⚀ \or ⚁ \or ⚂ \or ⚃ \or ⚄\or ⚅
+      \else
+         ⚅\HyPsd at DieFace{\numexpr#1-6}%
+      \fi
+  \fi
+}
+
+
+\def\HyPsd at ding#1{%
+  \ifnum#1<32 %
+    \HyPsd at UnicodeReplacementCharacter
+  \else
+    \ifnum#1>254 %
+        \HyPsd at UnicodeReplacementCharacter
+    \else
+        \ifnum#1<127 %
+          \ifcase\numexpr#1-33\relax
+            ✁\or ✂\or ✃\or ✄\or ☎\or ✆\or ✇\or ✈\or ✉\or ☛\or ☞% 33-43
+             \or ✌\or ✍\or ✎\or ✏\or ✐\or ✑\or ✒\or ✓\or ✔\or ✕% 44-53
+             \or ✖\or ✗\or ✘\or ✙\or ✚\or ✛\or ✜\or ✝\or ✞\or ✟%  54-63
+             \or ✠\or ✡\or ✢\or ✣\or ✤\or ✥\or ✦\or ✧\or ★\or ✩% 64-73
+             \or ✪\or ✫\or ✬ \or ✭\or ✮\or ✯\or ✰\or ✱\or ✲\or ✳% 74-83
+             \or ✴\or ✵\or ✶\or ✷\or ✸\or ✹\or ✺\or ✻\or ✼\or ✽% 84-93
+             \or ✾\or ✿\or ❀\or ❁\or ❂\or ❃\or ❄\or ❅\or ❆\or ❇%94-103
+             \or ❈\or ❉\or ❊\or ❋\or ●\or ❍\or ■\or ❏\or ❐\or ❑% 104-113
+             \or ❒\or ▲\or ▼\or ◆\or ❖\or ◗\or ❘\or ❙\or ❚\or ❛\or ❜%114-124
+             \or ❝\or ❞%125-126
+           \fi
+        \else% >126
+          \ifnum#1>160 %
+           \ifcase\numexpr#1-161\relax
+            ❡\or ❢\or ❣\or ❤\or ❥\or ❦\or ❧\or ♣\or ♦\or ♥\or ♠%161-171
+            \or ①\or ②\or ③\or ④\or ⑤\or ⑥\or ⑦\or ⑧\or ⑨\or ⑩%172-181
+            \or ❶\or ❷\or ❸\or ❹\or ❺\or ❻\or ❼\or ❽\or ❾\or ❿%182-191
+            \or ➀\or ➁\or ➂\or ➃\or ➄\or ➅\or ➆\or ➇\or ➈\or ➉%192-201
+            \or ➊\or ➋\or ➌\or ➍\or ➎\or ➏\or ➐\or ➑\or ➒\or ➓%202-211
+            \or ➔\or →\or ↔\or ↕\or ➘\or ➙\or ➚\or ➛\or ➜\or ➝%212-221
+            \or ➞\or ➟\or ➠\or ➡\or ➢\or ➣\or ➤\or ➥\or ➦\or ➧%222-231
+            \or➨ \or ➩\or ➪\or ➫\or ➬\or ➭\or ➮\or ➯ \or \HyPsd at UnicodeReplacementCharacter %232-240
+            \or ➱\or ➲\or ➳\or ➴\or ➵\or ➶\or ➷\or ➸\or ➹\or ➺%241-250
+            \or ➻\or ➼\or ➽\or ➾%251-254
+           \fi
+          \else %127-160
+            \HyPsd at UnicodeReplacementCharacter
+          \fi
+        \fi
+      \fi
+    \fi
+}
+
+\def\HyPsd at UnicodeReplacementCharacter{�}
+
+\def\HyPsd at DieFaceLarge{\ERROR}
+\def\HyPsd@@ding#1!{\ERROR}
+\endinput
diff --git a/testfiles-pool/newpdfstringdef.lvt b/testfiles-pool/newpdfstringdef.lvt
new file mode 100644
index 0000000..ca19703
--- /dev/null
+++ b/testfiles-pool/newpdfstringdef.lvt
@@ -0,0 +1,43 @@
+\documentclass{article}
+%\usepackage{ucs}
+%\usepackage[utf8x]{inputenc}
+\usepackage{CJK}
+\makeatletter
+\endlinechar \m at ne
+\def\CJK at namepppdef#1{
+  \CJK at active\protected\def#1{
+    \CJK@@@
+    \ifx\protect \@typeset at protect
+      \expandafter\expandafter\expandafter\CJK at XXX
+       \expandafter\string\expandafter#1
+    \else
+      \noexpand #1
+    \fi}}
+\endlinechar `\^^M
+\makeatother
+
+
+\usepackage{hyperref}
+\usepackage{new-pdfstring}
+\let\pdfstringdef\newpdfstringdef
+
+\usepackage{pifont}
+
+\begin{document}
+
+\section{\texorpdfstring{xx}{\unichar{2600}\texteuro\Cube{10}}}
+
+\section{\texorpdfstring{blub}{ΓειάσουΚόσμε}}
+
+
+\section{\texorpdfstring{blub}{字體字體}}
+
+%spaces?
+\section{grüße an die Welt}
+%ligatures
+\section{grüße---}
+
+\begin{CJK*}{UTF8}{bsmi}
+\section{字體字體}
+\end{CJK*}
+\end{document}





More information about the latex3-commits mailing list.