4

In Plain TeX when I do a \write containing ç or Ç in the string it gets expanded generating a lot of code in the output file, which can't be read back. I got this problem when reading a TOC:

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

I tried redefining \c c (this makes ç in Plain Tex) to \def\c #1 {\accent 24 #1} and it went good, but it is misaligned in \c C (Ç) and it's not related to the fonts, I've tried many.

I can't figure it out. Any ideas?

3
  • 1
    Welcome! Please post a small example document which can be used to reproduce the errors you are asking about.
    – cfr
    Nov 19, 2015 at 3:55
  • Thanks @cfr, here's the code: \openout 1 = test.out \write1 {OK sentence} \write1 {\c c not OK} \input test.out % put this after the first typesetting \bye
    – blmayer
    Nov 19, 2015 at 4:08
  • 1
    Use \noexpand\c c?
    – jon
    Nov 19, 2015 at 4:45

3 Answers 3

6

Since you're using pdftex, you can do better than prefixing each \c (or other accent) in a section title with \noexpand.

We want to add \protected in front of the definition of the accent macros. Since \c takes an argument, you can do it by

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

Now it's just a matter of abstracting this definition:

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

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

(add the accent you need). After this, \c in a section title will be written literally on the .toc file.

Full example

\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

Console output

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 output

enter image description here

1
  • I think, this should be added to LaTeX2e (or at least to LaTeX3 in the next century). Protected accents are a really good idea. Jan 10, 2016 at 9:41
6

You can use \noexpand in this case:

\write1 {\noexpand\c c is now OK :-)}
2
  • You were faster...
    – jon
    Nov 19, 2015 at 4:46
  • Oh..... Yep :-) Nov 19, 2015 at 5:05
3

You can use csplain. For example the command pdfcsplain. Input:

\input utf8lat1

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

\end

The console output:

>> 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).
2
  • I fear you have missed the point: the idea is to set the cedilla with the regular Plain macro \c, not with a specialized input/output encoding.
    – jarnosz
    Nov 19, 2015 at 18:13
  • @erreka IMHO, I didn't miss the point. The text in OP: "when I do a \write containing ç or Ç in the string it gets expanded" means that first problem were with ç or Ç in the string directly.
    – wipet
    Nov 20, 2015 at 7:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .