Sunday, 19 May 2013

Scan argument for parentheses

Scan argument for parentheses

I'd like to define a macro which expands to (#1) if #1 does not contain any parentheses, but expands to \big(#1\big) if it does.
I'd choose simplicity over generality: if a solution works in the most obvious use cases (i.e. \foo{x} and \foo{\sin(x)}, that would be enough for me. What's the easiest way to scan a macro argument for specific characters like this? Is there some package which already defines a ready-to-use “if stuff contains given character” kind of macro? Is there something useful in the LaTeX3 packages which are already available?
As an alternative to my approach, I'd also welcome some existing alternative to \left(#1\right) which ensures that the size chosen for the delimiters will always be bigger than the biggest size in the content, not merely as big as the content. I don't know if such a thing does exist, but if it does, it sure would be a useful thing, which could solve my above problem and a number of other ones besides.

No comments:

Post a Comment