SX. In this case, I want to create a \newcommand
named \fun
for function.
My problem arises when I use a \ fun
command again with the name f
(the letter f is widely used in my document) and avoid the first definition because otherwise, I will get the first case.
Minimal example
\documentclass{memoir}
\usepackage{amsmath,amssymb}
\usepackage{xstring}
\newcommand{\rn}[1][n]{%
\IfEqCase{#1}{%
{1}{\mathbb{R}}%
{2}{\mathbb{R}^{2}}%
{3}{\mathbb{R}^{3}}%
{n}{\mathbb{R}^{n}}
{#1}{\mathbb{R}^{#1}}
% You can add a finite number of more cases :)
}%
}%
\newcommand{\fun}[3][f]{%
\IfEqCase{#1}{
{f}{f\colon\mathcal{A}\rightarrow\mathcal{B}}
{g}{g\colon\mathcal{C}\rightarrow\mathcal{D}}
{#1}{#1\colon #2\rightarrow #3}
% Maybe "othercase" can generate case like f or g.
}
}
\begin{document}
If I use $f$ function like this $\fun[f]{\rn}{\rn[m]}$,
but I expect to use a function called $f\colon\rn\rightarrow\rn[m]$.
This example works fine, e.g, $\fun[\omega]{\rn}{\rn[1]}$ but I want to use
this command
%\fun[othercase]{f}{\rn}{\rm[1]}
\end{document}
This example works fine, e.g, $\fun[\omega]{\rn}{\rn[1]}$
.
If I use $f$
function like this $\fun[o]{f}{\rn}{\rn[m]}$
,
but I expect to use a function called $f\colon\rn\rightarrow\rn[m]$
.
Update
I tried to construct the command like this:
\newcommand{\fun}[5][default]{%
\IfEqCase{#1}{
{default}{
\IfEqcase{#2}{
{f}{#2\colon\mathcal{A}\rightarrow\mathcal{B}}
{g}{#2\colon\mathcal{C}\rightarrow\mathcal{D}}
}
}
{other}{
{}{#3\colon #4 \rightarrow #5}
}
}
}
Because I don't want lost the default options with f
(f\colon\mathcal{A}\rightarrow\mathcal{B}
) and g
(g\colon\mathcal{C}\rightarrow\mathcal{D}
) respectively.
I see that I need one optional argument inside other optional argument.
Source
I use this idea for create the command.
Thanks in advance!
$\fun[\omega]{\rn}{\rn[1]}$
is fine, but it gives a runaway argument error.$
as you have omitted the$
if you surround the expression with$
you get the error! Class memoir Error: Font command \rm is not supported.
because\rm
is not defined to do anything. perhaps you intended\rn
but neither of those errors are comnnected with your macros at all.