Re: How can I write "%" to a file?



Morten Høgholm wrote:


>> I want a LaTeX program to write the line "%&latex" to a Metapost file,
>> but when I say
>> \immediate\write\mpfile{%&latex}
>> I get an error, since % causes the rest of the line to be ignored.
>> On the other hand, if I say
>> \immediate\write\mpfile{\%&latex}
>> then "\%" is written to the file.
>>
>> How can I write an unadorned "%"?
>
> LaTeX has an internal \@percentchar which expands to a harmless %.

Thanks very much.
That works perfectly:
----------------------------------
\documentclass{article}

\newwrite\myfile

\begin{document}

\immediate\openout\myfile\jobname.out
\makeatletter
\immediate\write\myfile{\@percentchar}
\makeatother
\immediate\closeout\myfile

\end{document}
----------------------------------

It's not really clear to me why I can't just say \%,
but I guess that is one of the mysteries of life.


--
Timothy Murphy
e-mail (<80k only): tim /at/ birdsnest.maths.tcd.ie
tel: +353-86-2336090, +353-1-2842366
s-mail: School of Mathematics, Trinity College, Dublin 2, Ireland
.



Relevant Pages


Loading