15

I need to include some tex files as parts of a more global project. Some of this global projects have to be compiled with pdflatex, some others with lualatex, but the parts are the same. All this part files are written with a € as an utf8 character. I would like avoid to replace them by a \texteuro.

Is there a way to make lualatex understand € as a \texteuro ?

\documentclass[french]{article}
\RequirePackage{ifluatex}
\ifluatex
    \RequirePackage{fontspec}
    \RequirePackage{luacode}
\else
    \RequirePackage[utf8]{inputenc}
    \RequirePackage[T1]{fontenc}
\fi

\RequirePackage{fourier}

\begin{document}
36\,\texteuro % works with both pdflatex lualatex

36\,€ % doesn't work with lualatex
\end{document}
  • Perhaps something like Ctrl + H ? :) – Mario S. E. Nov 15 '14 at 8:56
  • I have a thousand files with such a remplacement to make. I can run a pearl script to make the changes. But if there is a simple solution to do this it is wellcome. One could ask why lualatex doesn't accept all utf8 characters ? Is there other characters that lualatex doesn't accept ? – Tarass Nov 15 '14 at 9:01
  • I can no possibility of checking now, hence only a suggestion. Does \catcode`\€=\active \def€{your euro, e.g. \texteuro} € work for you? – Przemysław Scherwentke Nov 15 '14 at 9:12
  • @PrzemysławScherwentke no, it gives 36 your euro and an infinite loop if a remplace your euro by € ;-) – Tarass Nov 15 '14 at 9:19
  • 1
    @Tarass Of course you should replace not by €, but by \texteuro or other command which produces the symbol. – Przemysław Scherwentke Nov 15 '14 at 9:22
10

You can use newunicodechar package and define

\newunicodechar{€}{\texteuro}

Code:

\documentclass{article}
\RequirePackage{ifluatex}
\ifluatex
    \RequirePackage{fontspec}
    \RequirePackage{luacode}
\else
    \RequirePackage[utf8]{inputenc}
    \RequirePackage[T1]{fontenc}
\fi
\let\hbar\hhhbar    %% without this I get a warning
\RequirePackage{fourier}

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

\begin{document}
36\,\texteuro % works with both pdflatex lualatex

36\,€ % doesn't work with lualatex
\end{document}

Then it should work in both pdflatex and lualatex.

  • It doesn't come from your code, but from a known clash between fourier and some math fonts. One has to load some math fonts before fourier. I have \RequirePackage{amsmath,amsfonts,amssymb,mathrsfs} before fourier package in my .sty. – Tarass Nov 15 '14 at 9:33
17

With \usepackage{fourier} you are simply ignoring fontspec and using a family of “classical” 256 character font.

You can use classical fonts with LuaLaTeX, without loading fontspec, but luainputenc:

\documentclass{article}
\usepackage{ifluatex}
\usepackage[TS1,T1]{fontenc} % load TS1 so luainputenc will know
\ifluatex
  \usepackage{luacode}
  \usepackage[utf8]{luainputenc}
\else
  \usepackage[utf8]{inputenc}
\fi

\usepackage{fourier}

\begin{document}
36\,\texteuro % works with both pdflatex lualatex

36\,€ % doesn't work with lualatex
\end{document}

Of course this will not use the full strengths of LuaLaTeX as regards to fonts, but it's impossible anyway if you want your document to be processable with LuaLaTeX and pdfLaTeX (and loading luacode doesn't make much sense).

A probably better solution is to use a text font replacement for Utopia, such as the very recent Erewhon font:

\documentclass{article}
\usepackage{ifluatex}
\ifluatex
  \usepackage{luacode}
  \usepackage{fourier}
  \usepackage{fontspec}
  \setmainfont{Erewhon}
\else
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{fourier}
\fi


\begin{document}
36\,\texteuro % works with both pdflatex lualatex

36\,€ % doesn't work with lualatex

Some math $a+\mathrm{a}=\int_{0}^{1} f(x)\,dx$
\end{document}

enter image description here

  • Thank you for this solution. I will not adopt it by now, because Erewhon is a very young package and is not support in texlive, that means that the solution is not immediatly portable. But I keep it in mind and the explantions you've give with. – Tarass Nov 15 '14 at 12:40
  • @Tarass Erewhon is in TeX Live. There's also Heuristica, which is similar. – egreg Nov 15 '14 at 13:38
  • tlmgr didn't find it on ` ftp.oleane.net/pub/CTAN/systems/texlive/tlnet`. I change of depository, and now it's ok. – Tarass Nov 15 '14 at 14:21
4

As it is already verified, I put also my solution, suggested in comments.

\documentclass{article}
\usepackage{fourier}
\catcode`\€=\active
\def€{\texteuro} 
\begin{document}
36 €
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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