bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PDF destination names for pdfTeX and LuaTeX


From: Masamichi Hosoda
Subject: Re: PDF destination names for pdfTeX and LuaTeX
Date: Tue, 09 Aug 2016 02:33:49 +0900 (JST)

>> I wonder if it's possible to put the code for getting the "destination
>> name" in a macro (a \def) so that it can be used when outputting a
>> target (e.g. @node) and when referring to a target (e.g. @xref or the
>> PDF sidebar). That could simplify the code and reduce duplication.
> 
> Sounds good.

I've created two patches.
One is for pdfTeX / Luatex.
The other is for XeTeX.

May I commit them?

ChangeLog:

2016-08-XX  Masamichi Hosoda  <address@hidden>

        * doc/texinfo.tex (\setpdfdestname): New macro for XeTeX.
        (\pdfdestname): Escaped PDF destination name
        is set by \setpdfdestname.
        (\setpdfoutlinetext): New macro for XeTeX.
        (\pdfoutlinetext): Converted and escaped outline text
        is set by \setpdfoutlinetext.
        (\pdfmkdest): Use \setpdfdestname.
        (\dopdfoutline): Use \setpdfdestname and \setpdfoutlinetext.
        (\xrefX): Use \setpdfdestname.
        
2016-08-XX  Masamichi Hosoda  <address@hidden>

        * doc/texinfo.tex (\setpdfdestname): New macro for pdfTeX and LuaTeX.
        (\pdfdestname): Escaped PDF destination name
        is set by \setpdfdestname.
        (\setpdfoutlinetext): New macro for pdfTeX and LuaTeX.
        (\pdfoutlinetext): Converted and escaped outline text
        is set by \setpdfoutlinetext.
        (\pdfmkdest): Use \setpdfdestname.
        (\dopdfoutline): Use \setpdfdestname and \setpdfoutlinetext.
        (\xrefX): Use \setpdfdestname.
--- texinfo.tex.org     2016-08-09 01:05:21.591393200 +0900
+++ texinfo.tex 2016-08-09 01:52:46.474094400 +0900
@@ -1338,7 +1338,7 @@
       \pdfrefximage \pdflastximage
     \fi}
   %
-  \def\pdfmkdest#1{{%
+  \def\setpdfdestname#1{{%
     % We have to set dummies so commands such as @code, and characters
     % such as \, aren't expanded when present in a section title.
     \indexnofonts
@@ -1362,9 +1362,53 @@
     \fi
     \def\pdfdestname{#1}%
     \txiescapepdf\pdfdestname
-    \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
   }}
   %
+  \def\setpdfoutlinetext#1{{%
+    \indexnofonts
+    \makevalueexpandable
+    \turnoffactive
+    \ifx \declaredencoding \latone
+      % The PDF format can use an extended form of Latin-1 in bookmark
+      % strings.  See Appendix D of the PDF Reference, Sixth Edition, for
+      % the "PDFDocEncoding".
+      \passthroughcharstrue
+      % Pass through Latin-1 characters.
+      %   LuaTeX: Convert to Unicode
+      %   pdfTeX: Use Latin-1 as PDFDocEncoding
+      \def\pdfoutlinetext{#1}%
+    \else
+      \ifx \declaredencoding \utfeight
+        \ifx\luatexversion\thisisundefined
+          % For pdfTeX  with UTF-8.
+          % TODO: the PDF format can use UTF-16 in bookmark strings,
+          % but the code for this isn't done yet.
+          % Use ASCII approximations.
+          \passthroughcharsfalse
+          \def\pdfoutlinetext{#1}%
+        \else
+          % For LuaTeX with UTF-8.
+          % Pass through Unicode characters for title texts.
+          \passthroughcharstrue
+          \def\pdfoutlinetext{#1}%
+        \fi
+      \else
+        % For non-Latin-1 or non-UTF-8 encodings.
+        % Use ASCII approximations.
+        \passthroughcharsfalse
+        \def\pdfoutlinetext{#1}%
+      \fi
+    \fi
+    % LuaTeX: Convert to UTF-16
+    % pdfTeX: Use Latin-1 as PDFDocEncoding
+    \txiescapepdfutfsixteen\pdfoutlinetext
+  }}
+  %
+  \def\pdfmkdest#1{%
+    \setpdfdestname{#1}%
+    \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
+  }
+  %
   % used to mark target names; must be expandable.
   \def\pdfmkpgn#1{#1}
   %
@@ -1392,72 +1436,13 @@
     % page number.  We could generate a destination for the section
     % text in the case where a section has no node, but it doesn't
     % seem worth the trouble, since most documents are normally structured.
-    {
-      \turnoffactive
-      \ifx \declaredencoding \latone
-        % The PDF format can use an extended form of Latin-1 in bookmark
-        % strings.  See Appendix D of the PDF Reference, Sixth Edition, for
-        % the "PDFDocEncoding".
-        \passthroughcharstrue
-        % Pass through Latin-1 characters.
-        %   LuaTeX: Convert to Unicode
-        %   pdfTeX: Use Latin-1 as PDFDocEncoding
-        \edef\pdfoutlinetext{#1}%
-        \iftxiuseunicodedestname
-          % Pass through Latin-1 characters.
-          % LuaTeX with byte wise I/O converts Latin-1 characters to Unicode.
-          \edef\pdfoutlinedest{#3}%
-        \else
-          % Use ASCII approximations in destination names.
-          \passthroughcharsfalse
-          \edef\pdfoutlinedest{#3}% 
-        \fi
-      \else
-        \ifx \declaredencoding \utfeight
-          \ifx\luatexversion\thisisundefined
-            % For pdfTeX  with UTF-8.
-            % TODO: the PDF format can use UTF-16 in bookmark strings,
-            % but the code for this isn't done yet.
-            % Use ASCII approximations.
-            \passthroughcharsfalse
-            \edef\pdfoutlinetext{#1}%
-            \edef\pdfoutlinedest{#3}% 
-          \else
-            % For LuaTeX with UTF-8.
-            % Pass through Unicode characters for title texts.
-            \passthroughcharstrue
-            \edef\pdfoutlinetext{#1}%
-            \iftxiuseunicodedestname
-              % Pass through Unicode characters for destination names.
-              \edef\pdfoutlinedest{#3}%
-            \else
-              % Use ASCII approximations in destination names.
-              \passthroughcharsfalse
-              \edef\pdfoutlinedest{#3}% 
-            \fi
-          \fi
-        \else
-          % For non-Latin-1 or non-UTF-8 encodings.
-          % Use ASCII approximations.
-          \passthroughcharsfalse
-          \edef\pdfoutlinetext{#1}%
-          \edef\pdfoutlinedest{#3}% 
-        \fi
-      \fi
-      %
-      \ifx\pdfoutlinedest\empty
-        \def\pdfoutlinedest{#4}%
-      \else
-        % LuaTeX: Use UTF-8
-        % pdfTeX: Use ASCII
-        \txiescapepdf\pdfoutlinedest
-      \fi
-      % LuaTeX: Convert to UTF-16
-      % pdfTeX: Use Latin-1 as PDFDocEncoding
-      \txiescapepdfutfsixteen\pdfoutlinetext
-      %
-      \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{\pdfoutlinetext}%
-    }
+    \setpdfoutlinetext{#1}
+    \setpdfdestname{#3}
+    \ifx\pdfdestname\empty
+      \def\pdfdestname{#4}%
+    \fi
+    %
+    \pdfoutline goto name{\pdfmkpgn{\pdfdestname}}#2{\pdfoutlinetext}%
   }
   %
   \def\pdfmakeoutlines{%
@@ -8933,35 +8918,18 @@
      %
      % This (wrongly) does not take account of leading or trailing
      % spaces in #1, which should be ignored.
-     \iftxiuseunicodedestname
-       \ifx \declaredencoding \latone
-         % Pass through Latin-1 characters.
-       \else
-         \ifx \declaredencoding \utfeight
-           % Pass through Unicode characters.
-         \else
-           % Use ASCII approximations in destination names.
-           \passthroughcharsfalse
-         \fi
-       \fi
-     \else
-       % Use ASCII approximations in destination names.
-       \passthroughcharsfalse
-     \fi
-     \def\pdfxrefdest{#1}%
+     \setpdfdestname{#1}%
      %
-     \ifx\pdfxrefdest\empty
-       \def\pdfxrefdest{Top}% no empty targets
-     \else
-       \txiescapepdf\pdfxrefdest  % escape PDF special chars
+     \ifx\pdfdestname\empty
+       \def\pdfdestname{Top}% no empty targets
      \fi
      %
      \leavevmode
      \startlink attr{/Border [0 0 0]}%
      \ifnum\filenamelength>0
-       goto file{\the\filename.pdf} name{\pdfxrefdest}%
+       goto file{\the\filename.pdf} name{\pdfdestname}%
      \else
-       goto name{\pdfmkpgn{\pdfxrefdest}}%
+       goto name{\pdfmkpgn{\pdfdestname}}%
      \fi
     }%
     \setcolor{\linkcolor}%
--- texinfo.tex.org     2016-08-09 01:55:27.421545900 +0900
+++ texinfo.tex 2016-08-09 02:07:51.070543000 +0900
@@ -1672,7 +1672,8 @@
   \def\pdfdest name#1 xyz{%
     \special{pdf:dest (#1) address@hidden /XYZ @xpos @ypos null]}%
   }
-  \def\pdfmkdest#1{{%
+  %
+  \def\setpdfdestname#1{{%
     % We have to set dummies so commands such as @code, and characters
     % such as \, aren't expanded when present in a section title.
     \indexnofonts
@@ -1686,37 +1687,37 @@
     \fi
     \def\pdfdestname{#1}%
     \txiescapepdf\pdfdestname
-    \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
   }}
   %
-  % by default, use black for everything.
-  \def\urlcolor{\rgbBlack}
-  \def\linkcolor{\rgbBlack}
-  \def\endlink{\setcolor{\maincolor}\pdfendlink}
-  %
-  \def\dopdfoutline#1#2#3#4{{%
+  \def\setpdfoutlinetext#1{{%
     \turnoffactive
     % Always use Unicode characters in title texts.
     \def\pdfoutlinetext{#1}%
     % For XeTeX, xdvipdfmx converts to UTF-16.
     % So we do not convert.
     \txiescapepdf\pdfoutlinetext
-    \iftxiuseunicodedestname
-      % Pass through Unicode characters.
-    \else
-      % Use ASCII approximations in destination names.
-      \passthroughcharsfalse
-    \fi
-    \def\pdfoutlinedest{#3}%
-    \ifx\pdfoutlinedest\empty
-      \def\pdfoutlinedest{#4}%
+  }}
+  %
+  \def\pdfmkdest#1{%
+    \setpdfdestname{#1}%
+    \safewhatsit{\pdfdest name{\pdfdestname} xyz}%
+  }
+  %
+  % by default, use black for everything.
+  \def\urlcolor{\rgbBlack}
+  \def\linkcolor{\rgbBlack}
+  \def\endlink{\setcolor{\maincolor}\pdfendlink}
+  %
+  \def\dopdfoutline#1#2#3#4{%
+    \setpdfoutlinetext{#1}
+    \setpdfdestname{#3}
+    \ifx\pdfdestname\empty
+      \def\pdfdestname{#4}%
     \fi
-    % Use UTF-8 or ASCII
-    \txiescapepdf\pdfoutlinedest
     %
     \special{pdf:out [-] #2 << /Title (\pdfoutlinetext) /A
-      << /S /GoTo /D (\pdfoutlinedest) >> >> }%
-  }}
+      << /S /GoTo /D (\pdfdestname) >> >> }%
+  }
   %
   \def\pdfmakeoutlines{%
     \begingroup
@@ -8947,18 +8948,10 @@
        %
        % This (wrongly) does not take account of leading or trailing
        % spaces in #1, which should be ignored.
-       \iftxiuseunicodedestname
-         % Pass through Unicode characters.
-       \else
-         % Use ASCII approximations in destination names.
-         \passthroughcharsfalse
-       \fi
-       \def\pdfxrefdest{#1}%
+       \setpdfdestname{#1}%
        %
-       \ifx\pdfxrefdest\empty
-         \def\pdfxrefdest{Top}% no empty targets
-       \else
-         \txiescapepdf\pdfxrefdest  % escape PDF special chars
+       \ifx\pdfdestname\empty
+         \def\pdfdestname{Top}% no empty targets
        \fi
        %
        \leavevmode
@@ -8972,10 +8965,10 @@
          % this command line option is no longer necessary
          % because we can use the `dvipdfmx:config' special.
          \special{pdf:bann << /Border [0 0 0] /Type /Annot /Subtype /Link /A
-           << /S /GoToR /F (\the\filename.pdf) /D (\pdfxrefdest) >> >>}%
+           << /S /GoToR /F (\the\filename.pdf) /D (\pdfdestname) >> >>}%
        \else
          \special{pdf:bann << /Border [0 0 0] /Type /Annot /Subtype /Link /A
-           << /S /GoTo /D (\pdfxrefdest) >> >>}%
+           << /S /GoTo /D (\pdfdestname) >> >>}%
        \fi
       }%
       \setcolor{\linkcolor}%

reply via email to

[Prev in Thread] Current Thread [Next in Thread]