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

Is there a way for including assertions in a LaTeX document? I want to check that some condition is true, and only allow compilation of the document if it is (or at least complain otherwise).

Specifically, a paragraph contains a reference to a chapter. Before compiling the final version, I'd like to be warned if the chapter is the current chapter, so that I could e.g. substitute the text with "in this chapter".

share|improve this question
up vote 6 down vote accepted

Here is an idea that goes a bit beyond your question. You can do this with the ifthen package and by defining a new command. The command \mychapterref{#1} checks if the argument (a reference) is the current chapter. If it is, it writes out the string this chapter, otherwise it writes out Chapter~\ref{#1}.



\ifthenelse{\equal{\ref{#1}}{\arabic{chapter}}}{this chapter}{Chapter~\ref{#1}}

look in \mychapterref{chap1}

look in \mychapterref{chap1}


The code above outputs

look in this chapter

in Chapter 1 and

look in Chapter 1

in other chapters.

share|improve this answer
Does this solution constrain me in the way I have to use labels? Would this still work if I had used the label \label{chapter:begin}? – Christian Lindig Mar 5 '11 at 6:13
@Christian: 1. no, 2. yes - just test it! – Hendrik Vogt Mar 5 '11 at 8:19
I've taken the liberty to try and improve your nice answer a bit. A tip: you can use backticks ` to mark your inline code. (Note the ~ and the % I added; the latter prevents the space that your command inserted in the beginning.) – Hendrik Vogt Mar 5 '11 at 8:22
Thanks for solving my immediate problem. I posted another question for the other part of my question. – Tim N Mar 5 '11 at 10:10
@Tim: Happy to help! I have been helped often by solutions on this site so it was nice to be able to help someone else! @Hendrik: thanks for the tips... My first time here! – jaydev Mar 5 '11 at 15:00

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.