0

I have defined three counters which I'm going to increment within a condition. This should lead to the result that functional requirements are prefixed with FA (and a subsequent number) and non functional requirements are prefixed with NFA (and a diffrent number sequence independent from the functional requirements). This should also apply for the general user story.

With the code below it seems that the counter will step regardless if the condition is met or not. Unfortunately I'm not quite sure if there would be a better solution or if I'm mistaking anything. Any comments would be highly appreciated!

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[scaled]{helvet}
\usepackage[T1]{fontenc}
\usepackage[left=4cm, right=2cm, top=4cm, bottom=2cm]{geometry}
\usepackage[style=long,nonumberlist,toc,acronym]{glossaries}


\newacronym{U}{U}{User Story(s)}
\newacronym{FA}{FA}{Funktionale Anforderung}
\newacronym{NFA}{NFA}{Nicht funktionale Anforderung}

\newcounter{UserStoryCounter}
\setcounter{UserStoryCounter}{1}

\newcounter{UserStoryCounterFA}
\setcounter{UserStoryCounterFA}{1}

\newcounter{UserStoryCounterNFA}
\setcounter{UserStoryCounterNFA}{1}

\newcommand{\userstory}[3]{
    \if\equal{#1}{\string FA}
        \paragraph{(#1\gls{FA}\arabic{UserStoryCounterFA}) #2}#3
        \stepcounter{UserStoryCounterFA}
    \else
        \if\equal{#1}{NFA}
            \paragraph{(#1\gls{NFA}\arabic{UserStoryCounterNFA}) #2}#3
            \stepcounter{UserStoryCounterNFA}
        \else
            \paragraph{(#1\gls{U}\arabic{UserStoryCounter}) #2}#3
            \stepcounter{UserStoryCounter}
        \fi
    \fi
}
\begin{document}

\userstory{FA}{}{}
\userstory{NFA}{}{}
\userstory{U}{}{}

\end{document}

2
  • 1
    also you should use % at ends of lines, \userstory adds two space tokens before \paragraph and two after, which may or may not affect the visual output, depending where the command is used. Jan 5 at 11:35
  • 1
    never ignore error messages Jan 5 at 11:36

2 Answers 2

1

The example produces the error

! Undefined control sequence.
\userstory #1#2#3-> \if \equal 

as \equal is not defined. If \equal was defined \if\equal{ would expand \equal and then test if the first two tokens in its expansion were the same character, or if its exansion was just one token, it would test if that is {

You could replace

\if\equal{#1}{\string FA}

by, for example,

\def\tmpa{#1}\def\tmpb{FA}\ifx\tmpa\tmpb
0

There is no \equal in TeX, unless you define it. Here's a much simpler method to define your command.

\documentclass[11pt,a4paper]{article}
%\usepackage[utf8]{inputenc} % no longer needed
\usepackage[scaled]{helvet}
\usepackage[T1]{fontenc}
\usepackage[left=4cm, right=2cm, top=4cm, bottom=2cm]{geometry}
\usepackage[style=long,nonumberlist,toc,acronym]{glossaries}


\newacronym{U}{U}{User Story(s)}
\newacronym{FA}{FA}{Funktionale Anforderung}
\newacronym{NFA}{NFA}{Nicht funktionale Anforderung}

\newcounter{UserStoryCounter}
\setcounter{UserStoryCounter}{1}

\newcounter{UserStoryCounterFA}
\setcounter{UserStoryCounterFA}{1}

\newcounter{UserStoryCounterNFA}
\setcounter{UserStoryCounterNFA}{1}

\ExplSyntaxOn

\NewDocumentCommand{\userstory}{mmm}
 {
  \str_case:nnF {#1}
   {
    {FA}{
     \paragraph{(#1\gls{FA}\arabic{UserStoryCounterFA})~#2}#3
     \stepcounter{UserStoryCounterFA}
    }
    {NFA}{
      \paragraph{(#1\gls{NFA}\arabic{UserStoryCounterNFA})~#2}#3
      \stepcounter{UserStoryCounterNFA}
    }
    %add other cases here
   }
   {% all other cases
    \paragraph{(#1\gls{U}\arabic{UserStoryCounter})~#2}#3
    \stepcounter{UserStoryCounter}
   }
 }
\ExplSyntaxOff

\begin{document}

\userstory{FA}{}{}

\userstory{NFA}{}{}

\userstory{U}{}{}

\end{document}

This can be easily extended to more than two cases, along the same lines.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .