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?

David Carlisle
  • 757,742
Martin
  • 4,565

3 Answers3

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}
TH.
  • 62,639
  • You could use \begingroup...\endgroup. Shows why you shouldn't, really. – Charles Stewart Sep 10 '10 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.) – Will Robertson Sep 10 '10 at 11:08
  • @Charles: I don't think \begingroup will work in this way. – Will Robertson Sep 10 '10 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 '10 at 11:17
  • "you could make $ just be a normal punctuation symbol" ... how would I do this? Link appreciated :-) – Martin Sep 10 '10 at 11:20
  • @Margin: \catcode`$12 – TH. Sep 10 '10 at 11:26
  • Change the catcode. The standard catcode of $ eg. is 3 = math shift (you can find the default settings at the start of latex.ltx) \catcode`$=3, change this to 12. You can write quite obscure TeX-Code by switching catcodes ;-) – Ulrike Fischer Sep 10 '10 at 11:28
  • @TH.,@Will: Right, the point is that these macros are expanded in Tex's stomach. You could use something like \def\Curry#1#2#3{#1{#2#3}} to turn streams of tokens into the right shape. Or, better, \def\apply#1\to#2\end{#1{#2}}. – Charles Stewart Sep 10 '10 at 12:32
  • @Charles: I don't follow. Which macros? Using delimited macros is a good idea. Of course, in the case of the plaintext environment I constructed, you'd need to use \apply\end\to{plaintext}. I'd probably be easier in that case to just define \plaintext with a \begingroup and \let\endplaintext\endgroup and then use \plaintext ... \endplaintext. – TH. Sep 10 '10 at 12:55
  • In your plaintext environment, with { and } set to catcode other, you could use the macro, say: normal \apply\textbf\to bold\end\ normal - this will group bold and pass it as argument to \textbf. You can't nest groupings using this macro, but you could define other macros to construct nested groupings. – Charles Stewart Sep 10 '10 at 16:40
  • @TH: I have no other way to contact you: interested in turning this into a package? I've been thinking of something like this for years. – Will Robertson Sep 14 '10 at 06:22
  • @TH.: I would say that reverting to normal catcodes in mathmode would be nice (or having a \normalcatcodes macro) – Bruno Le Floch Jan 11 '11 at 15:38
  • @Bruno: Both of those seem like a good ideas to me. – TH. Jan 11 '11 at 22:10
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)

Aditya
  • 62,301
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.