TeX - LaTeX Asked on August 3, 2020
To speed up my typesetting work I’m exploring the possibility to redefine
some commands “locally”.
In this particular case I’d like to redefine the big
, Big
, etc. commands to the left
and right
commands. The redefinition must be conditioned by the next-char (or next-regexp).
E.g. something like this “pseudo-code”:
newcommand{myRedefinedBigs}{%
COND 1 next char (or next regexp) is (or "(" "[" "{")
renewcommand{big}{left}
renewcommand{Big}{left}
renewcommand{bigg}{left}
renewcommand{Bigg}{left}
COND 2 next char (or next regexp) is (or ")" "]" "}")
renewcommand{big}{right}
renewcommand{Big}{right}
renewcommand{bigg}{right}
renewcommand{Bigg}{right}}
The idea is to wrap an equation with this command. E.g.:
{myRedefinedBigs
begin{equation}
big(frac{1}{2}big)
end{equation}}relax
Can this be made in LaTeX? If so, what do I need to looking for?
Edit. Wermer solution seemed to work but it fails in the case on nested pair of the same kind. E.g.:
{myRedefinedBigs
begin{equation}
big(frac{1}{2}big(3)big)
end{equation}}relax
Note.
I don’t write documents myself from scratch. I prepare the works of scientists to be published in physics journals. So I have to “correct” layout “errors” according to the guidelines provided.
The following assumes that you're using big
and friends in a paired form, similar to left
and right
. Also, it assumes opening delimiters are associated with left
and closing delimiters with right
. Any unmatched <delim>
iters revert back to big<delim>
.
documentclass{article}
makeatletter
newcommand{myRedefinedBigs}{%
letoldbigbig% Copy big into oldbig
defbig{% Redeine big
@ifnextchar({biglparen}{% big is followed by (
@ifnextchar){bigrparen}{% big is followed by )
@ifnextchar[{biglbracket}{% big is followed by [
@ifnextchar]{bigrbracket}{% big is followed by ]
@ifnextchar{{biglbrace}{% big is followed by {
@ifnextchar}{bigrbrace}{% big is followed by }
oldbig}}}}}}}% big is followed by something else, so resort to oldbig
defbiglparen({left(}% big( is replaced by left(
defbigrparen){right)}% big) is replaced by right)
defbiglbracket[{left[}% big[ is replaced by left[
defbigrbracket]{right]}% big] is replaced by left]
defbiglbrace{{left{}% big{ is replaced by left{
defbigrbrace}{right}}% big} is replaced by left}
letBigbig% Handle Big just like big
letbiggbig% Handle bigg just like big
letBiggbig% Handle Bigg just like big
}
makeatother
begin{document}
[
big(frac{1}{2}big)
]
{myRedefinedBigs
[
big(frac{1}{2}big)
]}
[
big(frac{1}{2}^{Big{frac{1}{2}Big]}big)
]
{myRedefinedBigs
[
big(frac{1}{2}^{Big{frac{1}{2}Big]}big)
]}
[
big(frac{1}{2}big(3big)big)
]
{myRedefinedBigs
[
big(frac{1}{2}big(3big)big)big|
]}
end{document}
Correct answer by Werner on August 3, 2020
A user is supposed to use opening and closing delimiters in its formulas. Moreover, you should not redefine a useful macro but use another macro as appropriate.
You can see different delimiters (sizes and shapes) in the following example. You can also see the opening and closing delimiters.
pi(n)=sum_{m=2}^nleftlfloorbiggl(sum_{k=1}^{m-1}
bigllfloor(m/k)big/lceil m/krceilbigrrfloorbiggr)^{-1}
rightrfloor
It is easy to replace opening and closing delimitors in the sample code.
Important: left
or right
followed by a delimiter don't always produce the expected delimiters (typographic aesthetics).
For instance, we can see two formatting of the same formula. The formula on the right corresponds to the formatting recommended in the TeXbook while the formula on the left could appear after replacing the corresponding modifiers (bigl
, biggr
...) by left
or right
in the above code snippet.
Moreover, the "modifiers" left
and right
must appear in the same part of the formula.
It is necessary to replace each "modifier" preceding a delimiter with the appropriate modifier.
These modifiers may be automatically replaced by their matching modifiers. The algorithm to be used does not seem very complicated. Its implementation probably must depend on a text editor, obviously not on (La)TeX.
Answered by Fólkvangr on August 3, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP