TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a macro, which saves a string (like the content of a label) to the aux file. During the next run, there should be a macro checking, if that string has been set in the last run or not.

My solution so far presented as an example:


        \expandafter\string\expandafter\xdef\expandafter\string\csname #1\endcsname{}%

    \ifcsdef{setValue}{value set}{value \emph{not} set}

    \ifcsdef{strange:value}{strange value set}{strange value \emph{not} set}

This results (after multiple compilations) in: enter image description here

So although the pair of \csxdefaux and \ifcsdef macros obviously works for normal strings, it fails for strings with special characters.

What would be a good way to achieve the same as with my solution but supporting a wide range of special characters like colons, digits, umlauts?

share|improve this question
up vote 12 down vote accepted

The issue is nothing to do with \ifcsdef, as it is testing correctly and giving the correct answer. To see why, we need to look at the .aux file. With your definition, the .aux file reads


which is then read back by LaTeX to defined \setValue (as required), and \strange as a delimited macro (wrong). The latter happens as : is an 'other' character at this point, and the tokenization you had before is lost when you write something to a file.

What you therefore need is the \csname ...\endcsname construct inside the .aux file. One working definition is


or using the etoolbox wrapper


I've detokenized #1 when it's read back in case something like babel has made anything active. (I'm not sure why you have \xdef, so went with \gdef instead.)

share|improve this answer
Brilliant answer, thanks very much. The \xdef is not needed in this simple example, it was a relic of a more complex use case. – Patrick Häcker Jul 22 '12 at 19:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.