1

I am having a problem with some code and I could use some help. I have been using this implementation for a long time now and no problems before.

Here is how I store all my variables

\newcommand{\@srulesI}{}
\newcommand{\@srulesII}{}
\newcommand{\srules}[2]{
    \renewcommand\@srulesI{#1}
    \renewcommand\@srulesII{#2}}%%%%%

Here is the logic for it.

\if\@srulesII\@emptymacro
\else
    \begin{minipage}{\linewidth}
        \raggedright
        {\bfseries \rule{0em}{1.5em}\@srulesI}

        \@srulesII
    \end{minipage}
\fi

These pieces of code work

\srules{}{}%%%%%
\srules{}{asdf}%%%%%
\srules{asdf}{}%%%%%
\srules{asdf}{asdf}%%%%%
\srules{asdf}{asdf\rule{0.5in}{0.5in}}%%%%%

This piece of code doesnt work, which is coincidentally the one I need.

\srules{asdf}{\rule{0.5in}{0.5in}}%%%%%

It gives an error of "Incomplete \if; all text was ignored after line 40. "

Does anyone know why? I dont know why the \rule makes the compiler have a fit.

Second question. Is what I am doing really the best way to declare and store variables? Cause I have like 50 variables and my .cls file is getting huge.

2

For macro-comparison, use \ifx, not \if:

enter image description here

\documentclass{article}

\makeatletter
\newcommand{\@srulesI}{}
\newcommand{\@srulesII}{}
\newcommand{\srules}[2]{
  \renewcommand\@srulesI{#1}
  \renewcommand\@srulesII{#2}}%%%%%
\newcommand{\@emptymacro}{}
\makeatother

\begin{document}

\srules{asdf}{\rule{0.5in}{0.5in}}%%%%%
\makeatletter
\ifx\@srulesII\@emptymacro
\else
  \begin{minipage}{\linewidth}
    \raggedright
    {\bfseries \rule{0em}{1.5em}\@srulesI}

    \@srulesII
  \end{minipage}
\fi
\makeatother

\end{document}

In answer to your second question, it really depends on your user interface. Note that arguments to macros are limited to 9, although that can be increased. A key-value interface in such instances are typically preferred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.