[texhax] Question about cwebmac.tex

Igor Liferenko igor.liferenko at gmail.com
Mon Feb 1 22:57:53 CET 2016


Hi all,

Is it possible that the following macros from cwebmac.tex makes \toksE
contain no expandable tokens at all?

    % now comes a routine to "sanitize" section names, for pdf outlines
    \def\makeolproctok{\tokprocessedfalse
      \let\next\makeolnexttok % default
      \ifx\nxt\outlinedone\let\next\outlinedone
      \else\ifx{\nxt \else\ifx}\nxt \Tnumfalse \instrfalse % skip braces
      \else\ifx$\nxt % or a $ sign
      \else\ifx^\nxt \addF^\else\ifx_\nxt \addF_% sanitize ^ and _
      \else\ifx\nxt\spacechar \addF\space
      \else\if\noexpand\nxt\relax % we have a control sequence; is it
one we know?
        \ifx\nxt~\addF\space
        \else\ifx\nxt\onespace\addF\space
        \else\the\usersanitizer
        \iftokprocessed\else\makeolproctokctli
        \iftokprocessed\else\makeolproctokctlii
        \iftokprocessed\else\makeolproctokctliii % if not recognised, skip it
        \fi\fi\fi\fi\fi
       \else  % we don't have a control sequence, it's an ordinary char
        \ifx/\nxt \addF{\string\/}% quote chars special to PDF with backslash
        \else\ifx(\nxt \addF{\string\(}\else\ifx)\nxt \addF{\string\)}%
        \else\ifx[\nxt \addF{\string\[}\else\ifx]\nxt \addF{\string\]}%
        \else\expandafter\makeolproctokchar\meaning\nxt
       \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
      \next
    }

What should be taken into account to convert the following three
commands to \directlua so, that they will behave the same way?

    \pdfoutline goto name {NOS} count -\secno {\outsecname}

    \pdfoutline goto num \the\toksA \expandafter{\the\toksE}}

    \pdfoutline goto num #3 count -\expnumber{chunk#2.#3} {#5}}}

Using David Carlisle's example with \directlua I get \foo in both
cases - with and without using \expandafter. Why?

    \directlua{
      function toutf16(str)
        tex.write(str)
      end
    }
    \pdfcompresslevel=0
    \newtoks\toksE
    \toksE{\foo}
    \def\foo{bar}
    \pdfoutline goto num 2 \expandafter{\directlua{toutf16("\the\toksE")}}
    x
    \pdfoutline goto num 3 {\directlua{toutf16("\the\toksE")}}
    x
    \bye

Best wishes,
Igor


More information about the texhax mailing list