3

I did not know that I should be using \binom instead of \choose (and I ignored all the warnings). Now, instead of manually changing it at all places where I used \choose, I think there should be a way to redefine \choose as \binom right?

However, I don't know how and cannot find how to do it.

Sebastiano
  • 54,118
  • 7
    the syntax is different, the main argument against \choose is the infix syntax (the final result is the same) so either leave it as it is or a simple editor replace should change the source code, there is no way to do anything in tex – David Carlisle Feb 24 '21 at 20:16
  • 2
    Are you willing and able to use LuaLaTeX? Please also tell us how you employ \choose. E.g., do you always enclose the full expression in curly braces, as in { 5 \choose 3 }? – Mico Feb 24 '21 at 20:17
  • 2
    @Mico even with luatex, using an input buffer callback to change \choose to \binom which then expands essentially to \choose seems a bit round-about. – David Carlisle Feb 24 '21 at 20:39
  • 1
    Thanks for the comments! Indeed, the simplest solution seems to do a find-replace. @Mico - yes, I am able to use LuaLaTex and yes I always enclose the expression in curly braces. – Another Grad student Feb 24 '21 at 20:43
  • @DavidCarlisle - Indeed, the OP should just edit his/her file and manually replace all \choose constructs in suitable ways. – Mico Feb 24 '21 at 21:13
  • If always between curly brackets, I guess a RegEx find+replace tool could make it quite easy even for many occurrences. – Andrestand Jan 16 '23 at 19:59

1 Answers1

2

Assuming you always enclose the infix-style arguments of \choose in curly braces, i.e., if you write ${n \choose k}$ rather than just $n \choose k$, the following LuaLaTeX-based approach may be of interest to you. It defines a Lua function and assigns it to LuaTeX's process_input_buffer callback to scan the input stream for instances of {...\choose...} and to convert them to equivalent \binom expressions before TeX starts its usual processing.

This approach does have a few limitations. In particular, it assumes that the two ... arguments of \choose don't contain further curly braces. A less-binding constraint, hopefully, is that the instances of {...\choose...} don't contain line breaks.

enter image description here

If you check the log file, you'll find that it doesn't contain any warnings of the type

Package amsmath Warning: Foreign command \atopwithdelims;
(amsmath)                \frac or \genfrac should be used instead
(amsmath)                 on input line 13.

That's because by the time LaTeX processes the input, it never "sees" any of the \choose instructions.

\documentclass{article}
\usepackage{amsmath} % for '\binom' macro
\usepackage{luacode} % for 'luacode' environment
\begin{luacode}
function choose2binom ( s )
   -- perform non-greedy pattern match for "1 or more instances of any character"
   return ( s:gsub ( "{(..-)\\choose(..-)}" , "\\binom{%1}{%2}" ) )
end
\end{luacode}
\AtBeginDocument{\directlua{luatexbase.add_to_callback (
    "process_input_buffer", choose2binom , "choose2binom" ) }}

\begin{document} ${5\choose3}$ ${ 10 \choose 4 }$ $ {n\choosek} $ \end{document}

Mico
  • 506,678