Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The following document infinite-loops:

\documentclass{article}
\usepackage{breqn}
\begin{document}

\newcommand{\allowbreaks}[2][,]{\begingroup
  \catcode`#1=\active
  \scantokens{%
    \edef#1{%
      \show\detokenize{#1}%
      \detokenize{#1}%
      \noexpand\allowbreak
    \show0%
    }%
    #2%
  }
\endgroup}

\allowbreaks{$,$}

\end{document}

LaTeX displays

> the character ,.
,->\show ,
          ,\allowbreak \show 0
l.113 \allowbreaks{$,$}

?

repeatedly.

If I type I\show into it's prompt, it gives me

> the character ,.
,->\show ,,
           \allowbreak \show 0
l.113 \allowbreaks{$,$}

That is, the token that it's expanding it a character, not a macro. How is this possible?

If I comment out the breqn line, it works fine. I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).

share|improve this question
    
It runs without error with my texlive 2010 installation –  David Carlisle Feb 7 '12 at 23:48

1 Answer 1

up vote 6 down vote accepted

When you say \detokenize{,}, the comma becomes a character of category code 12, so \show, will show the meaning of this character.

The \edef will define the active comma to expand to

\show,,\allowbreak\show0

where the two commas have category code 12.

But when breqn is loaded, the comma has mathcode "8000 and you are in math mode! So TeX follows its rules: after having shown the meaning of the comma it finds another comma and, having it category code 12 and mathcode "8000, TeX replaces it with the meaning it currently has as an active character. That is, to show the comma and to use a comma, which has category code 12 and mathcode "8000

Oops, infinite loop. :-)

share|improve this answer
1  
you should mention that to "disable" the comma, its mathcode should be set to the value before breqn is loaded. Either with \mathcode`\,=..., or with \mathchar`\,. –  Bruno Le Floch Feb 8 '12 at 0:44

Your Answer

 
discard

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.