ç 在 \write 和 \read 中不起作用

ç 在 \write 和 \read 中不起作用

在 Plain TeX 中,当我在字符串中执行\write包含çÇ时,它会被扩展,从而在输出文件中生成大量代码,这些代码无法读回。我在阅读目录时遇到了这个问题:

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdftex)
 restricted \write18 enabled.
entering extended mode
(./Dissertation.tex (./macros.tex) [0{/usr/local/texlive/2015basic/texmf-var/fo
nts/map/pdftex/updmap/pdftex.map}] [1] [2] [3]
Underfull \vbox (badness 10000) has occurred while \output is active [4]
Underfull \vbox (badness 10000) has occurred while \output is active [5]
(./Dissertation.toc
./Dissertation.toc:1: Undefined control sequence.
<argument> INTRODU{\setbox \z 
                              @ \hbox {c}\lineskiplimit -\maxdimen \unhbox \...

\tocsecentry #1#2->\line {\rm #1
                                 \dotfill \ #2}
l.1 ...ip \hideskip \crcr }}}{\accent "7E A}O }{7}

? 
Process aborted

我尝试重新定义\c c(这会使 Plain Tex 中的 ç)\def\c #1 {\accent 24 #1}并且效果很好,但它在\c C(Ç)中未对齐并且与字体无关,我已经尝试了很多。

我搞不懂。有什么想法吗?

答案1

由于您正在使用pdftex,因此您可以做得更好,而不是\c在章节标题中的每个(或其他重音)前面加上前缀\noexpand

我们要\protected在重音宏的定义前面添加。由于它\c接受一个参数,因此你可以通过以下方式执行此操作

\begingroup
\toks0=\expandafter{\c{#1}}
\edef\x{\endgroup
  \protected\def\noexpand\c##1{\the\toks0}}\x

现在只需抽象这个定义即可:

\def\protectaccent#1{%
  \begingroup
  \toks0=\expandafter{#1{##1}}%
  \edef\x{\endgroup
    \protected\def\noexpand#1####1{\the\toks0}}\x
}

\protectaccent\c
\protectaccent\'
\protectaccent\^

(添加您需要的重音符号)。此后,\c章节标题将直接显示在.toc文件上。

完整示例

\def\protectaccent#1{%
  \begingroup
  \toks0=\expandafter{#1{##1}}%
  \edef\x{\endgroup
    \protected\def\noexpand#1####1{\the\toks0}}\x
}

\protectaccent\c
\protectaccent\'
\protectaccent\^

\immediate\write20{\c c\'a}

{\tt\meaning\'}

\c c\'a\^o

\bye

控制台输出

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdftex)
 restricted \write18 enabled.
entering extended mode
(./protectaccent.tex
\c c\'a
[1{/usr/local/texlive/2015/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] )</us
r/local/texlive/2015/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/
local/texlive/2015/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb>
Output written on protectaccent.pdf (1 page, 22016 bytes).
Transcript written on protectaccent.log.

PDF 输出

在此处输入图片描述

答案2

\noexpand在这种情况下您可以使用:

\write1 {\noexpand\c c is now OK :-)}

答案3

您可以使用 csplain。例如命令pdfcsplain。输入:

\input utf8lat1

\immediate\write16{====== normal text: çáô}
text: çáô

\end

控制台输出:

>> pdfcsplain pok  
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdfcsplain)
 restricted \write18 enabled.
entering extended mode
 encTeX v. Jun. 2004, reencoding enabled.
(./pok.tex The format: csplain <Aug. 2014>.
The cs-fonts are preloaded and A4 size implicitly defined.
The utf8->iso8859-2 re-encoding of Czech+Slovak alphabet activated by encTeX
(/usr/local/texlive/2015/texmf-dist/tex/generic/enctex/utf8lat1.tex
UTF-8 declaration: LATIN-1 SUPPLEMENT, U+0080--U+00FF)
====== normal text: çáô
[1{/usr/local/texlive/2015/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] )</us
r/local/texlive/2015/texmf-dist/fonts/type1/public/cs/csr10.pfb>
Output written on pok.pdf (1 page, 4969 bytes).

相关内容