[Tex/LaTex] one character macros

macros

I would like to define a macro that has at most one token in length.

\w is the macro and anything after w is not treated as part of the macro name. \wTest is same as \w Test. I don't care if no other macros starting with w are messed up(at least in my document, since I don't use any). Obviously it shouldn't interfere with other packages.

Alternatively, if it is not possible to do so, I would like to be able to redefine some special character like ^ or | to do the job. I would, say, possibly like to use it without the .

So suppose I want | to type out something

\documentclass{article}

\def\|{hello\,}

\begin{document}
\|world

\end{document}

But I'd rather do |world. (my document is so simple with just two or three special macro's that it will make it much more logical to reduce these markups to the most simple representation possible. I, for example, will never use | or ^ in my document in any normal way so I can use them to represent some markup. I only have to deal with how tex interprets them) There is no risk in my own document since it's either plane text or very few tex/latex macros(I use \vspace and \hspace and a few simple environments like centering along with 3 of my own macros for marking up the plain text).

e.g.,

I might have

This is a |test paragraph^. 
\begin{center} and this^ is |centered \end{center}

where | and ^ might be rather complex(long) markup that clutters up the original paragraph. in fact, it would be nice to even get rid of the envrionments:

This is a |test paragraph^.
<and this^ is |centered>

(notice how the second one is so much more readable than the first)

Best Answer

I think your first suggestion (a macro called \w such that \wTest is treated the same as \w Test) would require a lot of hacking. For the second you just have to set the catcode of the relevant character to \active.

\documentclass{article}
\catcode`|=\active
\def|{abc}
\begin{document}
|
\end{document}