I'd like to have a command with optional input that does the following:
if there is no input the output would be A_{ab}
if I input [cd] the output would be A_{ab to cd}
At the moment I use \newcommand like this \newcommand{\A}[1][]{\ensuremath{A_{ab #1}}}
but in this way I have to input "to cd" instead of "cd"... not a big deal but when I'll have to insert something more complex it will become annoying
Is there a way to make \newcommand do it or some better alternative that someone knows about?
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
I think I'm missing something: your reply seems logically what should do the job but doesn't work as I expected, in the No Value option the second option is executed with no value,
I changed a little the code to make it clearer I hope:
I think I found the problem. If no argument is inserted, an empty value is returned which is different from a "NoValue" value, therefore \IfNoValueTF returns always false.
I found a couple of soutions to deal with the problem:
The first does not require packages but uses some somewhat cryptic Tex code:
Sorry for my carelessness. I overlooked the narrow comma in the output and mistakenly assumed that in this case you could ignore the difference to the replacement commands for \newcommand.
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p