[texhax] Question about cwebmac.tex
Igor Liferenko
igor.liferenko at gmail.com
Fri Feb 5 11:52:31 CET 2016
The problem is solved.
Here is "toutf16" function and the patch to make non-ascii characters
in \pdfoutline:
\directlua{
function toutf16(str)
tex.write(string.char(92) .. "376" .. string.char(92) .. "377")
for c in string.utfvalues(str) do
if c < 0x10000 then
tex.write(string.char(92) .. string.format("%03o", c / 256) ..
string.char(92) .. string.format("%03o", c % 256))
else
c = c - 0x10000
local c1 = c / 1024 + 0xD800
local c2 = c % 1024 + 0xDC00
tex.write(string.char(92) .. string.format("%03o", c1 / 256) ..
string.char(92) .. string.format("%03o", c1 % 256) ..
string.char(92) .. string.format("%03o", c2 / 256) ..
string.char(92) .. string.format("%03o", c2 % 256))
end
end
end
}
--- cwebmac.tex.orig 2016-02-05 17:41:58.027390224 +0700
+++ cwebmac.tex 2016-02-05 17:48:24.999751085 +0700
@@ -474,10 +474,10 @@
\ifacro \def\outsecname{Names of the sections} \let\Xpdf\X
% \ifpdftex \makebookmarks \pdfdest name {NOS} fitb % in versions < 3.68
\ifpdftex \pdfdest name {NOS} fitb % changed in version 3.68
- \pdfoutline goto name {NOS} count -\secno {\outsecname}
+ \pdfoutline goto name {NOS} count -\secno
{\directlua{toutf16("\outsecname")}}
\def\X##1:##2\X{\Xpdf##1:##2\X \firstsecno##1.%
{\toksF={}\makeoutlinetoks##2\outlinedone\outlinedone}%
- \pdfoutline goto num \the\toksA \expandafter{\the\toksE}}
+ \edef\NEXT{\noexpand\pdfoutline goto num \the\toksA
{\noexpand\directlua{toutf16(string.gsub([[\the\toksE]],string.char(92),""))}}\NEXT}
\else\ifpdf
\special{pdf: outline -1 << /Title (\outsecname)
/Dest [ @thispage /FitH @ypos ] >>}
@@ -494,7 +494,7 @@
\expandafter\xdef\csname#1\endcsname{\the\countA}}
\def\writebookmarkline#1#2#3#4#5{{%
\let\(=\let \let\)=\let \let\[=\let \let\]=\let \let\/=\let
- \pdfoutline goto num #3 count -\expnumber{chunk#2.#3} {#5}}}
+ \pdfoutline goto num #3 count -\expnumber{chunk#2.#3}
{\directlua{toutf16(string.gsub([[#5]],string.char(92),""))}}}}
\def\con{\par\vfill\eject % finish the section names
% \ifodd\pageno\else\titletrue\null\vfill\eject\fi % for duplex printers
\rightskip 0pt \hyphenpenalty 50 \tolerance 200
I use string.gsub + [[ ]] to remove all backslashes. The special
characters will be converted by toutf16 function anyway and thus need
not be escaped. \NEXT is used instead of \next because \next is
already used in cwebmac.tex and I'm not sure if redefining it will not
have side effects.
Thanks to everyone,
Igor
More information about the texhax
mailing list