xifthen 和 fixme 之间有冲突吗?

xifthen 和 fixme 之间有冲突吗?

鉴于以下 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}

使用 pdflatex 编译时出现以下错误,除非我注释掉第 7 行和第 11 行或第 8 行 - 第 10 行。有没有办法解决这个明显的冲突?

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{

答案1

问题在于,该参数\fxwarning通过了\protected@edef,但\ifthenelse未能幸存。

\ifthenelse你可以通过在外部进行测试来实现这一点,但需要重复一些代码\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}

或者您可以使用更强大的方法。使用\NewDocumentCommand,参数说明符o用于标记可选参数;如果存在,\IfValueTF{#1}条件将遵循 true 分支。在这里,由于 false 分支将为空,因此我使用\IfValueT{#1}只需要一个参数即可获得 true 文本的 。

\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}

请注意,在任何情况下,可选参数都必须放在方括号中。

在此处输入图片描述

答案2

这里有很多错误。

  1. \needscitation在第二种情况下,你没有正确使用。你[me]不需要{me}

  2. 与 LaRiFaRi 一样,我遇到了不同的错误。

该测试(使用etoolbox代替)效果很好

\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}

相关内容