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 example gives when compiled with pdflatex the error

! Text line contains an invalid character.

\documentclass{article}
\usepackage{ifluatex}
\ifluatex
\usepackage{fontspec}
\fi
\begin{document}
abc
\ifluatex ^^^^20ac\fi
\end{document}

It is possible to get around the problem by using another char and changing its catcode e.g. inside the ifluatex:

\ifluatex{\catcode`\!=7 !!!!20ac}\fi

But I'm wondering: Is there a way to hide such invalid characters from ^^^^-notation in some way globally in pdflatex?

share|improve this question
    
\ifluatex\input{20ac.unicode}\fi and have a file for each unicode character. But that doesn't sound like a good solution, does it? :-/ –  tohecz Apr 23 at 8:31
    
@tohecz: sound like cheating ;-). Also one would probably get problems in some places (additional spaces, \input not allowed). –  Ulrike Fischer Apr 23 at 8:40
    
I think the easiest thing is to not use ^^^^^ but instead just use the character directly in utf-8 € then you can load \usepackage[utf8]{inputenc} for pdftex –  David Carlisle Apr 23 at 8:48
    
couldn't you use \char"20AC instead of ^^^^20ac? –  Herbert Apr 23 at 8:51
    
@Herbert: In some places certainly but you couldn't e.g. change the catcode of ^^^^20ac. –  Ulrike Fischer Apr 23 at 9:00

1 Answer 1

up vote 10 down vote accepted

The invalid character is ^^^, that is, 0x1E; LaTeX, by default, makes all characters from 0x01 to 0x1F invalid, with the exception of

0x09 0x0C 0x0D

that is, tab, line feed and carriage return (category codes 10, 13 and 5).

A workaround could be making this character ignored:

\documentclass{article}
\usepackage{ifluatex}
\ifluatex
  \usepackage{fontspec}
\else
  \catcode`\^^^=9
\fi
\begin{document}
abc
\ifluatex ^^^^20ac\fi
\end{document}

Assuming you don't need ^^^ anywhere in pdflatex code, this should keep TeX happy.

share|improve this answer
    
Imho this is perfect. I can't imagine what harm it should do as ^^^ would give an error anyway. –  Ulrike Fischer Apr 23 at 9:09
    
This is so genuine! –  tohecz Apr 23 at 10:51

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.