I often have cause to typeset things like this in TeX:
When reading expressions like the one above, it's very difficult to tell which brackets match each other. I'd like to be able to define variants of '(' and ')' that were typeset differently depending on the nesting level, to make it easier to match up the parentheses.
I can envisage doing this by introducing commands that increment/decrement some counter (to track the nesting level), and then use the current value of the counter to select the appropriate typesetting mechanism. But I have the impression that using a counter in that way is not very TeXish. What is the best way to do this?
It's not central to the question, but the code that generated the excerpt above is:
\documentclass[a4paper]{article}
\usepackage{libertine}
\begin{document}
$\textrm{subset}(\textrm{applyfn}(\textrm{inverse}(\mathbf{f}),\textrm{union2}(\mathbf{A},\mathbf{B})),\textrm{applyfn}(\textrm{union2}(\textrm{applyfn}(\textrm{inverse}(\mathbf{f}),\mathbf{A}),\textrm{inverse}(\mathbf{f})),\mathbf{B}))$
\end{document}
A solution that involved replacing (
and )
in that with commands would be fine.
Incidentally, editors sometimes have a facility called 'rainbow parentheses' which achieves the same effect; cf.
I don't actually want to use colour, because it's too garish (and I don't want to be forced to use a colour printer), but the desired effect is essentially the same. Suggestions on subtler alternatives to colour would be very welcome.
Edit: greyscale (using Ryan Reich's method) is pretty but ineffective:
underset numbers (a little distracting):
underlines (easy matching but distracting):
\langle
) so far. The replacement seems problematic if your language already assigns meaning to the new symbols or the usable ones are too far of to be recognized as paranthesis like objects. – Max Dec 30 '12 at 22:02TeX
macros as well. See tug.org/TUGboat/tb15-3/tb44doumont.pdf and www.tug.org/TUGboat/tb19-3/tb60wolin.pdf (although what you need is more like a LISP prettyprinter). – Ethan Bolker Dec 30 '12 at 22:08