1

Algorithm2e lets you define functions using \SetKwFunction{Fn}{Function} which you can then reference anywhere in the document (not just in an algorithm environment) using e.g. \Fn (which will output Function all nicely typeset in the right font). However, this doesn't work inside captions. For example, the following doc:

\documentclass{article}
\usepackage{algorithm2e}
\SetKwFunction{Fn}{Function}
\begin{document}
\begin{algorithm}
  \caption{\Fn, my function}
  \KwRet{0}\;
\end{algorithm}
\end{document}

dies with

Argument of \@caption has an extra }.
<inserted text> 
                \par 
l.6   \caption{\Fn, my function}

Anyone know what's going on, and how to fix it?

  • 2
    \caption{\protect\Fn my function} should work. – Benjamin Feb 9 '16 at 2:32
  • That did work. If you make this a comment an answer, I'll mark it as correct :-) – Nate Feb 19 '16 at 4:59
2

The macro has to be protected that it can be used inside caption:

\caption{\protect\Fn my function}

For more information why this is needed have a look at this question:

What is the difference between Fragile and Robust commands?

|improve this answer|||||

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.