josephwright / beamer

A LaTeX class for producing presentations and slides
Other
1.41k stars 142 forks source link

compile error with newunicodechar #805

Closed lupinchen closed 1 year ago

lupinchen commented 1 year ago
\documentclass{beamer}

\usepackage{newunicodechar}
\newunicodechar{€}{}

\def€#1€{{\bfseries #1}}

\begin{document}
€test€
\end{document}

Result

Package newunicodechar Warning: Redefining Unicode character on input line 4.

./test.tex:7: Use of � doesn't match its definition.
<recently read> ... \expandafter �\expandafter {�}

l.7 \begin{document}

? 

Environment

Texlive 2022 with beamer v3.68 (works on a different system with beamer v3.65)

samcarter commented 1 year ago

I get the same error with v3.65.

davidcarlisle commented 1 year ago

You seem to be using pdftex in which case \def€ can not do anything useful, it does not define € but byte E2 so prevents utf-8 decoding of an entire block of characters

davidcarlisle commented 1 year ago

If you need to define non-ascii characters in pdflatex you need to define them via latex inputenc declarations not \def

\documentclass{beamer}

\usepackage{newunicodechar}
\newunicodechar{€}{\qqq}

\def\qqq#1€{{\bfseries #1}}

\begin{document}
€test€
\end{document}
lupinchen commented 1 year ago

I must say that I don't really understand your answer but this version works fine. Thanks a lot.

Regarding your answer: \def€ cannot do anything useful... The code works as expected (by me) if I replace the \documentclass by article; then the \def€#1€ does seem to do something useful.

davidcarlisle commented 1 year ago

@lupinchen

\def€#1€ does seem to do something useful.

UTF-8 € is the three bytes E2 82 AC so you are defining byte E2 and so every character with leading byte E2 can no longer be decoded as a Unicode character and all of them except € will give low level tex errors.

so all characters from U+2000 (E2 80 80) to U+2FFF (E2 BF BF)

This typesets a dagger with pdflatex, but completely breaks if you uncomment the euro definition. Almost all common math symbols such as ∀ are in this U+2xxx range and similary broken by the definition. (over 4000 characters are broken)

\documentclass{article}

\usepackage{newunicodechar}
\newunicodechar{€}{}

% NO!!!!! 
% \def€#1€{{\bfseries #1}}

\begin{document}

dagger †

\end{document}
lupinchen commented 1 year ago

Ok. So the initial code with documentclass article was only working because I didn't use other unicode characters. Thanks a lot.