9

One thing I find annoying about (La)TeX is that there are too many special characters. To have any of \ $ % & # _ ~ ^ { } in a text in the document we have to escape it using \.

Personally I think this is stupid - after all we are writing a text document and not doing programming.

I think it would be great if there was a mode where we only have one escape character (and \ would suite me just fine) and all commands and control sequences would have to be preceded by \. Comments would be (e.g.) \% math could be introduced with \$ etc.

Are there any packages/hacks/modifications that allow this?

3 Answers 3

11

I can't answer your question about any packages that do that. Some of those parameters could be changed. For example, if you alway use \( ... \) instead of $...$, then you could make $ just be a normal punctuation symbol (or you could use \$). Likewise, \&, \_ and \^ could easily be swapped with their nonslashed counterparts. There's no need for ~ to be active, you could easily define \~ to have the same effect. As Will notes in the comments, # can be made a symbol.

I wasn't able to get comments working. I can't figure out how to get a macro to expand to an end of line token. Actually, I'm not even sure that's one of the tokens that gets to TeX's "stomach."

The real problem would come with braces. You really do need two additional characters to act as groupings. You could make two characters you don't frequently use be those.

So barring braces being special and not having line comments (although it'd be easy to define a block comment like \def\%#1\relax{} which might be sufficient for your purposes), this seems to work.

\newenvironment{plaintext}{%
        \catcode`\$12
        \def\&{&}%
        \catcode`\&12
        \def\_{_}%
        \catcode`\_12
        \def\^{^}%
        \catcode`\^12
        \catcode`\#12
        \catcode`\%12
        \let\~~%
        \catcode`\~12
}{}

Use it like

\begin{plaintext}
Here is some test text % ^ & _ $ # &.

How about some math \(x\_y\^z\). You're still out of luck with braces
though.
\end{plaintext}
13
  • You could use \begingroup...\endgroup. Shows why you shouldn't, really. Sep 10, 2010 at 11:07
  • Don't forget #, which can be turned into a letter as soon as your macro definitions are all done with. (Well, this might perhaps break some obscure code that uses \scantokens, but you're probably safe.) Sep 10, 2010 at 11:08
  • @Charles: I don't think \begingroup will work in this way. Sep 10, 2010 at 11:10
  • @Charles: Do you mean \bgroup...\egroup? This didn't work for me. I can never remember the rules for when you can use implicit braces, but I don't believe this is one of those times.
    – TH.
    Sep 10, 2010 at 11:17
  • "you could make $ just be a normal punctuation symbol" ... how would I do this? Link appreciated :-)
    – Martin
    Sep 10, 2010 at 11:20
7

In ConTeXt, we are discussion adding a macro \asciimode which will set catcodes such that only \, {, } and spaces (tab, newlines, and pagefeed) have their usual meaning. Everything else (including % and $) are set to other.

You can enter into math mode using \math{...}, display math mode using \startformula, comments using \starthidden, etc. Inside the math mode, _ and ^ have their usual meaning. There will be a dedicated 'programming' environment that will restore the traditional TeX catcodes.

A preliminary version is at the end of http://source.contextgarden.net/tex/context/base/catc-ctx.tex (although commented out at present)

1
  • 1
    It looks to me like ~ is left active. Sep 10, 2010 at 20:22
5

LuaTeX defines primitives for single char control sequences used in TeX:

\Usuperscript           ^
\Usubscript             _
\Ustartmath             $
\Ustopmath              $
\Ustartdisplaymath      $$
\Ustopdisplaymath       $$

So one can use these primitives in a way or another and set the catcode of those special characters to normal. This leaves percent sign, but I think if really needed, one can define a different comment character to replace it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.