# alternative syntax of subscripts using tex

I would like to sometimes write subscripts using different syntax, instead of $u_{xx} blahblah$ write something like

1. $u⎵xx blah blah$, or even
2. $u⎵xx+blah blah$

where either space following the x in 1. or the plus sign in 2. kicks its out of the subscript.

Is this possible to do using something clever in TeX?

-I am using XeLatex

-
Is that intentionally Unicode Character 'BOTTOM SQUARE BRACKET' (U+23B5)? –  Qrrbrbirlbel Jan 30 at 19:32
Also I want Windows to work properly. But some things are just meant to be :) –  percusse Jan 30 at 19:36
the unicode character triggers this new syntax (I want to do something similar to my question tex.stackexchange.com/questions/94957/…), the difference here is that a character such as space or + is enough to exit (rather than a bracket) –  georg raba Jan 30 at 19:36
@percuße I believe TeX is flexible enough to do this –  georg raba Jan 30 at 19:37
It is possible but I don't think it's worth it considering all the exceptions. –  percusse Jan 30 at 19:49

It's really not a good idea to this in a document but as a TeX exercise, this has pdftex and xetex versions:

\documentclass{article}

\ifx\XeTeXmathchar\undefined
% E2 8E B5
\catcode"E2\active
\else
\catcode"23B5\active
\fi
\def⎵{\sb\bgroup\xcollectsub}
\def\xcollectsub{\afterassignment\collectsub\global\let\tmp= }
\def\collectsub{%
\ifcat a\tmp
\tmp\expandafter\xcollectsub
\else
\egroup\expandafter\tmp
\fi}
\begin{document}

$u⎵xx blah blah$, or even
$u⎵xx+blah blah$

\end{document}

-
Why not recommend these answers? Which is least likely to break? –  georg raba Jan 30 at 20:12
The two answers are similar (I think the other one is assuming xetex/luatex but that could easily be extended to pdftex as in this one) Changing syntax is usually a bad idea. LaTeX isn't just an typesetting implementation, it should be thought of as a language, and if you make constructs that do not match the language syntax, they will confuse editors or convertors other than tex which and they usually will not mix and nest well with other latex constructs. Neither version is robust so will fail in captions and moving arguments (that's fixable) neither really works for nested subscripts.... –  David Carlisle Jan 30 at 20:29
I'm marking this one as the accepted answer because it works for an arbitrary number of subscripts. –  georg raba Jan 30 at 20:35
Also, can this be made to work with numeric characters ie u_01 ? –  georg raba Feb 6 at 4:31
@georgraba TeX is quite powerful enough to write parsers for any kind of syntax (I wrote a more or less complete xml+namespaces parser for example) but it's just a really bad idea to do that in the middle of a latex document. –  David Carlisle Feb 6 at 11:04

Not reccommended!

The ⎵'' hallo bit only shows that ⎵ is not active within text mode.

## Code

\documentclass{article}
\usepackage{ltxcmds}
\makeatletter
\let\qrr@openbrace={
\begingroup
\catcode⎵=\active
\gdef ⎵{\qrr@subscript{}{}}
\gdef\qrr@subscript#1#2{%
\ltx@ifnextchar@nospace{ }{_{#1#2}}{%
\@ifnextchar+{_{#1#2}}{%
\@ifnextchar-{_{#1#2}}{%
\@ifnextchar\qrr@openbrace{\qrr@subscript@{#1#2}}{\qrr@subscript{#1#2}}}%
}%
}%
}
\gdef\qrr@subscript@#1#2{% groups the second argument
\qrr@subscript{#1}{{#2}}%
}
\endgroup
\makeatother
\mathcode⎵="8000
\begin{document}
⎵'' hallo                       \par
$u ⎵xx f⎵rz$                     \par
$u ⎵xx+ x⎵rz- f⎵x\mathrm{text}x$ \par
$f⎵x{ab \over cd}y$
\end{document}


## Output

-
strongly agree that this isn't recommended, but one might ask, since you've made it happen, why you can't fix things so that the braces around \mathrm{text} aren't needed either. (you've really asked for that request to be made.) –  barbara beeton Jan 30 at 21:04
@barbarabeeton I guess I did ask for it. I haven’t thought about that much to be honest. Of course, {text} lost its grouping by becoming #2 of the main macro. I could fix things, though, so that the braces aren’t needed. The auxiliary macro \qrr@subscript@ groups its second argument before handing it back over to the main macro \qrr@subscript. –  Qrrbrbirlbel Jan 30 at 21:38