
pax.sty
XeLaTeX に適応させようとしたところ、.pax
ファイル内の URL が 16 進数としてエンコードされていることがわかりました。
\[{annot}{1}{Link}{56.693 693.9 156.107 707.7}{URI}{
URI={\<6D61696C746F3A68656C6C6F406578616D706C652E636F6D\>},
Border={[0 0 0]},
}\\
デコードされたURIは(で見ることができます)mailto:[email protected]
xxd -r -p
XeLaTeX で 16 進行をデコードするにはどうすればよいでしょうか (16 進数から ASCII へ)?
MWE:
\documentclass{article}
\newcommand{\hextotext}[1]{#1} % ???
\begin{document}
\hextotext{6D61696C746F3A68656C6C6F406578616D706C652E636F6D}
\end{document}
答え1
\str_set_convert:Nnnn
を使用すると、(仮定)から に変換utf8/hex
できます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}
次のように出力されます:
答え2
特別なケース「16進数からアスキー「(質問に記載されているように)たとえば、シーケンス全体を小文字にして、このシーケンスの連続する 2 つの文字の前に常に挿入すると、たとえば、-表記法の対応する文字シーケンス^^
として解釈されるものが得られます。\scantokens
^^
\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}
しかし、これはあくまでも遊び目的です。
実際のシナリオではPhelype Oleinik の回答で提供されているもの。これは、utf8/hex から utf8 への変換をカバーしていますが、ASCII (私の回答でカバーされているもの) は utf8 のサブセットにすぎません。