You can detect whether one is given or not:.
check if a parameter is empty
You'll see that this works by using a lower case 'o', whereas the upper case 'O' then requires a default value which I've made empty by including an empty group. This is probably how you should do it—that will look better with the rest of your LaTeX code. Creating a new environment with optional parameters is done similarly with. If you really want a command in the other form, see the end of my answer. The TeX FAQ has an answer about writing commands with more than one optional argument.
There are two options to how to do it. The underlying idea is to define a command which takes an optional argument, and then runs another command which itself takes an optional argument, etc. First, you define a command which takes a required argument, stores it in a macro, and then forward it onto another command.
XeTeX and LaTeX: Newcommand with an optional argument
Log In Sign Up. Join the Stack Overflow Community. Stack Overflow is a community of 7.
Join them; it only takes a minute: I'm experimenting with my own commands and environments and now I'm facing those latex newcommand optional argument empty Crowley 1, 5 15 Using the xparse package part of the LaTeX3 development efforts: You can detect whether one is given or not: Joseph Wright 2, 14 I've never seen this package before—that's really cool!
A particular issue is if the macro is used incorrectly, with the optional arg being ommitted: The error messages will have poor readability with your code: I'm not sure what I think about checking for [ —you're right that it will behave unexpectedly, but it actually has a perfectly well-defined behavior printing Required: The actual advice I would give is "don't use this technique"—while it's technically possible, it's probably a bad idea.
Thank you very much for your time spent on this issue. Consider also the xargs package. The following is an example from its documentation. Sign up or log in StackExchange. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3. Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.