I am keeping track of all the journal papers I review, and of course I'm using LaTeX.

There are different journals I review for and I have different tables and counters keeping track of papers. Each journal has it's own section---something similar to this:

IEEE Transactions on Power Systems (2)

  1. Title of the first paper, my decision, editor's decision.
  2. Title of the second paper, my decision, editor's decision.

IEEE Transactions on Power Delivery (1)

  1. Title of the first paper, my decision, editor's decision.

I have defined environments and commands to automate things as much as possible. I want to be able to show the number of papers at the beginning of my document; therefore, I'm using totcount package. Then simply writing something like (after defining TPWRD as a "total" counter)

Total number of TPWRD papers: \total{TPWRD}

does the trick. But I also want to show this number in the section title, as shown above in the parenthesis, and in the table of contents. My problem is that using \total as part of a section/subsection title gives me the error "Undefined control sequence." This happens without any parametrization. That is, even

\section{Simple Section \total{TPWRD}} 

results in an error. Using

\section[Simple Section]{Simple Section \total{TPWRD}}

avoids the problem by showing the counter value only in the section title and not in the table of contents. How can I have both?

I have also tried \protect\total{TPWRD}, but it results in another error: Missing number, treated as zero.

Here's a MWE:






\section{Journals \total{TPWRD}}  

  • 3
    A wild guess... have you tried putting \protect\total{TPWRD}?
    – user11232
    Commented Apr 27, 2012 at 7:51
  • @HarishKumar \protect does the trick. You should make an answer. Commented Apr 27, 2012 at 8:43
  • 2
    See: tex.stackexchange.com/questions/4736/… Commented Apr 27, 2012 at 9:38
  • @HarishKumar, Yes, I did try \protect. I should've mentioned this in my question. \protect\total{TPWRD} gives me another error: Missing number, treated as zero. Commented Apr 27, 2012 at 14:58
  • 1
    The problem with hyperref is that the computation for \total cannot be performed when preparing the bookmark text. So a non perfect remedy is to say \section{Journals \texorpdfstring{\protect\total{TPWRD}}{}}. It's not perfect because the number won't appear in the bookmark.
    – egreg
    Commented Apr 27, 2012 at 15:46

3 Answers 3


Your MWE will not work without \protect. Earlier I had no idea that you are using hyperref. Your MWE works in the following form:


\usepackage{hyperref}   % It does work even with hyperref.




\section{Journals \texorpdfstring{\protect\total{TPWRD}}{}}  % Works only with  \protect and also with  hyperref




enter image description here

PS: By adding a full MWE with your question, you will be helping us to avoid wasting time and the probability that you will get an accurate answer, also increases.

  • Thanks. As @egreg mentioned above, this solution does not show the "total" value in the bookmarks, but it does what I was looking for. Commented Apr 28, 2012 at 3:06

The argument of the \section command may be used for more than just producing a section title such as toc entries, running headings etc. When we use a fragile command inside a \section command, it will get broken while being moved around between different files/places (like .toc etc). The command \total is not a robust command (ie., it is fragile). Naturally, when it is used in a moving argument like \section, it will get broken and one will get an error. To prevent this we have to \protect the fragile commands like


When we use \section[Simple Section]{Simple Section \total{TPWRD}}, the short title will be moving around in toc etc and the main argument will be used only for producing the section headings. Hence errors will not be seen. But the toc entries will not carry the total counts of whatever you intend.

  • as I also mentioned above, \protect won't work with this. I should've mentioned this in my question (will update). Perhaps it's the way totcount is implemented and perhaps doesn't define certain commands until certain points? Commented Apr 27, 2012 at 15:04
  • @dochar: Also, it will be better if you add a MWE showing the problem. Otherwise we will be left making wild guess all through.
    – user11232
    Commented Apr 27, 2012 at 15:08
  • Harish, it doesn't even get past the first run because of the error. Commented Apr 27, 2012 at 15:09

The definition of \total in totcount.sty is far from perfect, but works well outside of moving arguments such as section titles.

I propose you to use, in those situations, a different command:


so that

\section{Journal \stotal{TPWRD}}

will work with or without hyperref. It won't give warnings if the number is still not defined, though.

You must log in to answer this question.

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