[latex3-commits] [git/LaTeX3-latex3-pdfresources] testlink: additional key for href and unicode input (a94193f)

Ulrike Fischer fischer at troubleshooting-tex.de
Sun Mar 14 23:56:48 CET 2021


Repository : https://github.com/latex3/pdfresources
On branch  : testlink
Link       : https://github.com/latex3/pdfresources/commit/a94193fad93734997beeac0047e7b26dc656f556

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

commit a94193fad93734997beeac0047e7b26dc656f556
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Sun Mar 14 23:56:48 2021 +0100

    additional key for href and unicode input


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

a94193fad93734997beeac0047e7b26dc656f556
 experiments/linkinput.tex | 53 +++++++++++++++++++++++++++++++++++++----------
 hyperref-generic.dtx      | 29 ++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/experiments/linkinput.tex b/experiments/linkinput.tex
index df8889c..8a46ddd 100644
--- a/experiments/linkinput.tex
+++ b/experiments/linkinput.tex
@@ -9,8 +9,33 @@
 \usepackage[T1]{fontenc}
 \usepackage{hyperref}
 \newcommand\cs[1]{\texttt{\textbackslash #1}}
+
+\makeatletter
+
+
+\ExplSyntaxOn
+
+\ExplSyntaxOff
+
+\makeatother
 \begin{document}
 
+%\href[encode]{www.öäü%§(.de}{blblbl}
+%
+%%\hypersetup{encode}
+%
+%%\href{www.öäü§(.de}{seöäüß}
+%
+%\href[encode=false]{www.abc%25(xxx.de}{seöäüß}
+
+\href[encode]{www.%.de}{abc}   %-> www.%25.de
+\href{www.%.de}{abc}           %-> www.%.de
+\href[encode]{www.grüße.de}{abc} %-> www.gr%C3%BC%C3%9Fe.de
+% \href{www.grüße.de}{abc} % error
+\href[encode]{grüße}{abc} %-> (gr\303\274\303\237e.pdf)
+
+\href{filexxx}{seöäüß}
+\end{document}
 \section{Some background about URL's with hyperref}
 
 hyperref has three commands related to URL: \cs{url},
@@ -22,14 +47,17 @@ while the last has two, the url and some free text.
 type, \cs{href} create URI, GoToR and Launch depending on the structure of the argument.
 
 \cs{href} has to create a (in the PDF) valid url or file name from its first argument.
-\cs{url} has to create a (in the PDF) valid url from its first argument and has to print 
-the url. \cs{nolinkurl} only prints the url.
+\cs{url} has to create a (in the PDF) valid url from its only argument and has to print
+this argument as url. \cs{nolinkurl} only prints the url.
 
 For the printing \cs{url} and \cs{nolinkurl} rely on the url package and its \cs{Url} command.
 
-(Expandable) commands are expanded and special chars can also be input by commands but beside this
-no conversion is done: for all input hyperref basically assumes that the input is a valid percent encoded url or
-a valid file name.
+(Expandable) commands are expanded and special chars can also be input by commands but beside this no conversion is done: for all input hyperref basically assumes that the input is already a valid percent encoded url or a valid file name.
+
+
+\href{https://www.abc(blub).de}{xxx}
+\end{document}
+
 
 %\begingroup
 %\makeatletter
@@ -168,8 +196,9 @@ The percent is not escaped, but in pdfmanagement it is!!
 \makeatother
 \section{non ascii}
 Is expanded to commands
-\href{https://www.xyz.deöxxx}{xxx}
-\url{https://www.xyz.deöxxx}
+%\href{https://www.xyz.deöxxx}{xxx}
+%\href{filewithnonasciiöäüxxx}{xxx}
+%\url{https://www.xyz.deöxxx}
 
 %loops
 %\href{https://www.xyz.de§xxx}{xxx}
@@ -178,12 +207,13 @@ Is expanded to commands
 Works more or less but is nonsense and errors with
 pdfmanagement.
 \fontencoding{T1}\selectfont
-\href{https://www.xyz.deöxxx}{xxx}
-\url{https://www.xyz.deöxxx}
+\href{filewithnonasciiöäüxxx}{xxx}
+%\href{https://www.xyz.deöxxx}{xxx}
+%\url{https://www.xyz.deöxxx}
 
 % expanded to \\T1\\ss\040
-\href{https://www.xyz.deßxxx}{xxx}
-\url{https://www.xyz.deßxxx}
+%\href{https://www.xyz.deßxxx}{xxx}
+%\url{https://www.xyz.deßxxx}
 
 
 %\section{simple command}
@@ -257,6 +287,7 @@ only direct input works
 
 \href{https://www.xyz.de#blub}{xxx}
 \href{https://www.xyz.de\#blub}{xxx}
+\href{filehash#blub}{xxx}
 \url{https://www.xyz.de#blub}
 \url{https://www.xyz.de\#blub}
 
diff --git a/hyperref-generic.dtx b/hyperref-generic.dtx
index b3b64c7..dd75a50 100644
--- a/hyperref-generic.dtx
+++ b/hyperref-generic.dtx
@@ -1066,7 +1066,36 @@
     }
   }
 %    \end{macrocode}
+% Allow non-ascii in href.
+% This needs an explicit option, as the encoding method must be changed.
 %
+%    \begin{macrocode}
+\newif\ifHy at encode
+\define at key{href}{encode}[true]
+  {
+    \Hy at boolkey{encode}{#1}
+  }
+\DeclareRobustCommand*{\href}[1][]{%
+  \begingroup
+  \setkeys{href}{#1}
+  \ifHy at encode
+   \let\protect\@unexpandable at protect
+   \tl_set:Nn \l__hyp_text_enc_uri_print_tl {utf8/URI}
+  \else
+   \tl_set:Nn \l__hyp_text_enc_uri_print_tl {utf8/string}
+  \fi
+  \@ifnextchar\bgroup\Hy at href{\hyper at normalise\href@}%
+}
+
+\keys_define:nn { hyp / setup }
+  {
+    ,encode .choice:
+    ,encode / true .code:n = { \Hy at encodetrue }
+    ,encode / false .code:n = { \Hy at encodefalse }
+    ,encode .default:n = {true}
+    ,encode .initial:n = {false}
+  }
+%    \end{macrocode}
 % \section{Compability commands}
 % \subsection{Metadata}
 % A number of values should be accessible from other packages. Until now





More information about the latex3-commits mailing list.