|
From: Mojca M. <moj...@gm...> - 2011-02-24 14:35:46
|
On Wed, Feb 23, 2011 at 22:36, Peter Hedwig wrote:
> Am Mittwoch, 23. Februar 2011 schrieb sfeam (Ethan Merritt):
>
> Providing a translation table would be better, because some characters can
> be escaped with a backslash, others like tilde "~" should be translated to
> \textasciitilde{} or $\sim$.
I agree at least with the point that one cannot treat special
characters in a uniform way (there is no simple transformation like
"add a backslash in front of a character" that would make all the
characters work).
>> But is there an all-purpose escape mechanism in TeX?
You could modify strings by replacing each $ with \$ etc., but it is
almost impossible to cover them all; in particular, modification that
might work with LaTeX may not work with ConTeXt etc.
The only really reliable way is to redefine \catcode-s of all special
characters and enter "a special mode" before reading the string and
quitting it after we're done.
>> That is, can you mark a string somehow so that every character in
>> it is printed with no interpretation or processing whatsoever?
>
> AFAIK there is no such mechanism. There are packages that do similar things,
> e.g. "verbatim", "listings" or "url" for LaTeX but I don't know any that
> works with all TeX flavors.
ConTeXt offers
\type{some %$^ \command}
but LaTeX has a different syntax, requires different packages, plain
TeX is yet different, just like Peter said.
The only reliable way to do it is the following:
- First, you need to select a command that will start literal string,
but most important: a sequence that will end it (that is the most
tricky part). You could print out something like
\beginverbatim some \weird %$^_ string \not \interpreted \endverbatim
Implementing \beginverbatim is easy ... apart from the fact that you
need to catch \endverbatim and you need to be aware that
set title "abc \some \harmless \command $% \enverbatim %"
will fail or you will need even more extra trickery.
- You need to define \beginverbatim at the begining of file that you
output with latex terminal (or one could put that definition to
gnuplot-tikz-common.tex for example). It has to redefine all the
catcodes, lccodes etc. Basically it needs to reimplement what packages
like verbatim or listings do in LaTeX, so that it won't switch the
font to typewriter, yet it will handle characters literally. It has to
be portable between plain/latex/context. (Honestly I'm not sure how to
handle UTF-8 characters in plain TeX.)
This requires a skilled TeX freak (or somebody who takes time to study
the TeXbook and code that handles verbatim in LaTeX and/or ConTeXt as
some hints). I know only approximately what needs to be done, but I
would need an enormous amount of time to come up with implementation
(I'm not sure how to implement the string that quits verbatim).
However there are some mailing list where people might be willing to
help with that.
Mojca
|