3

Given the following MWE:

\documentclass[draft]{scrbook}

\usepackage{xifthen}
\usepackage{fixme}

\newcommand\needscitation[1][]{%
  \fxwarning{citation needed%
    \ifthenelse{\isempty{#1}}%
    {}% if #1 is empty
    {: #1}% if #1 is not empty
  }
}

\begin{document}

Lorum Ipsum \needscitation
Lorum Ipsum \needscitation{me}

\end{document}

I get the following error when compiling with pdflatex, unless I comment out either line 7 & 11 or 8 - 10. Is there a way to resolve this apparent conflict?

compiling mwe.tex...
mwe.tex:17: Undefined control sequence \isempty.
mwe.tex:17: leading text: L
mwe.tex:17: Argument of \@tempc has an extra }.
mwe.tex:17: leading text: L
mwe.tex:17: Paragraph ended before \@tempc was complete.
mwe.tex:17: leading text: L
mwe.tex:17: Argument of \@tempc has an extra }.
mwe.tex:17: leading text: L
mwe.tex:17: Paragraph ended before \@tempc was complete.
mwe.tex:17: leading text: L
mwe.tex:17: Argument of \@tempc has an extra }.
mwe.tex:17: leading text: Lorum Ipsum \needscitation{
mwe.tex:17: Paragraph ended before \@tempc was complete.
mwe.tex:17: leading text: Lorum Ipsum \needscitation{
mwe.tex:17: Argument of \@tempc has an extra }.
mwe.tex:17: leading text: Lorum Ipsum \needscitation{
mwe.tex:17: Paragraph ended before \@tempc was complete.
mwe.tex:17: leading text: Lorum Ipsum \needscitation{
  • I am getting different errors. Please try to reduce your MWE to the minimum, get rid of unused options and use standard classes such as article. Makes it easier for us. Make sure, your MWE produces just the errors your describe. – LaRiFaRi Mar 16 '15 at 10:31
  • You're right; I was compiling using rubber, I should have posted the output of a plain pdflatex call. – retorquere Mar 16 '15 at 12:11
2

The problem is that the argument to \fxwarning passes through \protected@edef and \ifthenelse doesn't survive it.

You can do it at the expense of some code duplication, by having the \ifthenelse test outside \fxwarning

\documentclass[draft]{scrbook}

\usepackage{xifthen}
\usepackage{fixme}

\newcommand\needscitation[1][]{%
  \ifthenelse{\isempty{#1}}
    {\fxwarning{citation needed}}%
    {\fxwarning{citation needed: #1}}%
}

\begin{document}

Lorum Ipsum \needscitation
Lorum Ipsum \needscitation[me]

\end{document}

or you can use a more robust approach. With \NewDocumentCommand, the argument specifier o is used to mark an optional argument; if present, the \IfValueTF{#1} conditional will follow the true branch. Here, since the false branch would be empty, I use \IfValueT{#1} that requires just one argument for the true text.

\documentclass[draft]{scrbook}

\usepackage{xparse}
\usepackage{fixme}

\NewDocumentCommand\needscitation{o}{%
  \fxwarning{citation needed\IfValueT{#1}{: #1}}%
}

\begin{document}

Lorum Ipsum \needscitation
Lorum Ipsum \needscitation[me]

\end{document}

Note that, in any case, the optional argument must go in square brackets.

enter image description here

5

Many things wrong here.

  1. You are not using the \needscitation correctly in the second case. you need [me] not {me}

  2. As LaRiFaRi I get a different error.

This test (using etoolbox instead`) works fine

\documentclass{article}
\usepackage[draft]{fixme}
\usepackage{etoolbox}
\newcommand\needscitation[1][]{%
  \fxwarning{citation needed%
    \ifblank{#1}{}{%
      : #1}%
  }
}

\begin{document}

Lorum Ipsum \needscitation
Lorum Ipsum \needscitation[me]

\end{document}
  • 1
    I wish I could mark to entries as the answer. I'm going with the one egreg only because it has more details on the cause, not because I think your answer is less valuable. – retorquere Mar 16 '15 at 12:13

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.