
pax.sty
Ich werde versuchen , es für XeLaTeX anzupassen und habe festgestellt, dass die URL in .pax
den Dateien als Hex-Zeile codiert ist:
\[{annot}{1}{Link}{56.693 693.9 156.107 707.7}{URI}{
URI={\<6D61696C746F3A68656C6C6F406578616D706C652E636F6D\>},
Border={[0 0 0]},
}\\
Die dekodierte URI ist (kann durch angezeigt werden )mailto:[email protected]
xxd -r -p
Wie kann ich Hex-Zeilen in XeLaTeX dekodieren (Hex zu ASCII)?
MWE:
\documentclass{article}
\newcommand{\hextotext}[1]{#1} % ???
\begin{document}
\hextotext{6D61696C746F3A68656C6C6F406578616D706C652E636F6D}
\end{document}
Antwort1
Sie können \str_set_convert:Nnnn
zur Konvertierung von (angenommen) utf8/hex
nach verwenden utf8
:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\str_new:N \l__ivanov_tmpa_str
\NewDocumentCommand \hextotext { o m }
{
\str_set_convert:Nxnn \l__ivanov_tmpa_str {#2}
{ utf8/hex } { utf8 }
\IfValueTF{#1}
{ \str_set_eq:NN #1 \l__ivanov_tmpa_str }
{ \str_use:N \l__ivanov_tmpa_str }
}
\cs_generate_variant:Nn \str_set_convert:Nnnn { Nx }
\ExplSyntaxOff
\begin{document}
\hextotext{6D61696C746F3A68656C6C6F406578616D706C652E636F6D}
\hextotext[\tmp]{6D61696C746F3A68656C6C6F406578616D706C652E636F6D}
\texttt{\meaning\tmp}
\end{document}
Dies druckt:
Antwort2
Im Sonderfall „hex toASCII" (wie in Deiner Frage angegeben) Du kannst zB die ganze Folge kleinschreiben, immer ^^
vor zwei aufeinanderfolgende Zeichen dieser Folge einfügen, und schon hast Du etwas, was zB von \scantokens
als die entsprechende Zeichenfolge in ^^
-Notation interpretiert wird.
\documentclass{article}
\begingroup
\makeatletter
\catcode`\^^A=14\relax
\catcode`\%=12\relax
\@firstofone{^^A
\endgroup
\newcommand\hextotext[2]{^^A
\@ifdefinable#1{^^A
\lowercase{^^A
\scantokens\expandafter{^^A
\expandafter\newcommand\expandafter#1\expandafter{^^A
\romannumeral\expandafter\hextotextloop\expandafter{\expandafter}\detokenize{#2}\relax\relax
}%^^A
}^^A
}^^A
}^^A
}^^A
}%
\begingroup
\makeatletter
\catcode`\^=12\relax
\@firstofone{%
\endgroup
\newcommand*\hextotextloop[3]{%
\ifx\relax#2\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\z@#1}{\hextotextloop{#1^^#2#3}}%
}%
}%
\begin{document}
% 6D61696C746F3A68656C6C6F406578616D706C652E636F6D
^^6d^^61^^69^^6c^^74^^6f^^3a^^68^^65^^6c^^6c^^6f^^40^^65^^78^^61^^6d^^70^^6c^^65^^2e^^63^^6f^^6d
\hextotext{\MyCommand}{6D61696C746F3A68656C6C6F406578616D706C652E636F6D}
\begingroup
\ttfamily
\string\MyCommand: \meaning\MyCommand
\endgroup
\MyCommand
\end{document}
Aber das ist nur zum Herumspielen gedacht.
In realen Szenarien würde ich verwendenwas in der Antwort von Phelype Oleinik steht.Dies umfasst die Konvertierung von UTF8/Hex in UTF8, während ASCII (was in meiner Antwort behandelt wird) nur eine Teilmenge von UTF8 ist.