I would like to define a newcommand
with two optional arguments, which in turn, calls on another command with two optional arguments.
Something like the following (\B
calls \A
). How do I do it?
\newcommand{A}[3][][]{{#1 + #2 + #3}}
\newcommand{B}[3][][]{#1 + \A[#2][#3]{#1}}
\B{9}
\B[1][]{9}
\B[][3]{9}
\B[1][3]{9}
EDIT
I tried to give a similar MWE, but I am afraid that the above example actually may not properly convey exactly what I need.
The reason I had this question is to create a command that takes in a certain bib-item and highlights it. I would like to pass two optional arguments to \parencite[pre][post]{#1}
(where pre
and post
could be empty) via a newcommand \hlcite[pre][post]{#1}
. The command \hlcite
would then highlight the references.
\usepackage{graphicx, color}
\usepackage[dvipsnames]{xcolor}
\usepackage{bookmark}
\usepackage[
backend=biber, % backend: biber
style=authoryear, % style: numeric-comp, authoryear
sorting=ynt, % sorting: none, ynt
]{biblatex}
\usepackage{soul}
\newcommand{\hlc}[2][yellow]{\sethlcolor{#1} \hl{#2}}
%% This works
\newcommand{\hlcite}[1]{\colorbox[green]{\mbox{\parencite{#1}}}}
%% But this throws error
\newcommand{\hlcite}[3]{\hlc[green]{\mbox{\parencite[#2][#3]{#1}}}}
References
Adding optional arguments
- How do I add optional arguments in newcommand?
- Pass blank as argument to a command
- Special behavior if optional argument is not passed
- https://stackoverflow.com/questions/2144176/latex-newcommand-default-argument-is-empty
- https://stackoverflow.com/questions/1812214/latex-optional-arguments
- Optional argument for newcommand?
- \newcommand to create a command with optional arguments
- Passing optional arguments to a command with also optional arguments
- Empty optional argument or Not giving optional argument at all?
- xparse: forward empty optional argument
- Pass 3 optional arguments in newcommand
Non-stackoverflow/stackexchange links:
- https://www.overleaf.com/learn/latex/Commands?
- TeXFAQ: More than one optional argument
- Optional Arguments in LaTeX Macros
- https://riptutorial.com/latex/example/28656/if-statements
- LaTeX \if condition
- You can't use `macro parameter character #' in restricted horizontal mode.
References to use \mbox
with \cite
or \parencite
inside \newcommand
for highlighting.
- YouTube Video: How to highlight citations in LaTeX
- Problems with \ref when using soul for highlighting
- https://stackoverflow.com/questions/58391698/how-to-highlight-references-numbers-and-citations-in-overleaf
- How to highlight citations in a revised manuscript
- https://texblog.org/2015/05/20/using-colors-in-a-latex-document/amp/