I'm trying to write a little Latex package to learn more about Tex and to help me out with writing long and annoying proofs for a course by creating macros to retrieve rule names from a table given the rules number (which is given in a arbitrary compendium).
But I'm having severe problems with calling macros from within a macro.
This is my code:
%macro for formatting rules
\newcommand{\nR}[1]{%
=\;\{\text{{#1}}\}%
}
%Prints the rule specified by the argument from the nametable in a nice formatting
\newcommand{\Rnl}[1]{%
&\\&\nR{\nT{{#1}}}\\&%
}
%rule nametable
\newcommand{\nT}[1]{%
\stringcases
{#1}%
{%
{1.1}{Axiom of whatever}%
{2.1}{Silly theorem}%
}%
{\mathbf{UNDEFINED\_RULE\;\;{#1}}}%
}
%I got these from:
% http://tex.stackexchange.com/questions/64131/implementing-switch- cases
\newcommand{\stringcases}[3]{%
\romannumeral
\str@case{#1}#2{#1}{#3}\q@stop
}
\newcommand{\str@case}[3]{%
\ifnum\pdf@strcmp{\unexpanded{#1}}{\unexpanded{#2}}=\z@
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\str@case@end{#3}}
{\str@case{#1}}%
}
\newcommand{\str@case@end}{}
\long\def\str@case@end#1#2\q@stop{\z@#1}
But the problem is that when I call from a math environment \Rnl{1.1} I get a \mathbf allowed only in math mode. although if I change \mathbf
to \textbf it will output {UNDEFINED_RULE 1.1}. Which it shouldn't do since there is a case matching 1.1.
The really confusing thing is that if i just call \nT{1.1} it will output "axiom of whatever" so that macro works as long as I don't call it from within another macro.
Below follows a compilable example of how I aim to use it:
\documentclass{article}
\usepackage{amsmath}
%%Insert macros from above here.
\begin{document}
What I want want to be able to write:
\begin{align*}
& A \wedge B \Rnl{1.1} Bob \Rnl{2.1} T
\end{align*}
What I want to get:
\begin{align*}
&A \wedge B \\
&=\;\text{\{The rule that coresponds to 1.1 in the name table\}} \\
&Bob\\
&=\;\text{\{The rule that coresponds to 2.1 in the name table\}} \\
&T
\end{align*}
\end{document}
How can I solve this?
What is the difference between
– Henrik Sommerland Oct 06 '15 at 13:10\DeclareRobustCommandand\newcommand??\DeclareRobustCommandhere however. – Oct 09 '15 at 06:03