47

I'd like to use the \hl command from the soul package in a French text. However, it does not work whenever the part to highlight contains French accents (e.g.: \hl{é}).

I could use \'e instead of é (\hl{\'e}) but it would be quite long to substitute all the accents just in case I will have to highlight them later (and there are several accents in French : é, è, ù, à, ...).

Do you know whether it's possible to make \hl works with accents without substituing all the accents?

Here is an example file:

\documentclass[15pt , a4paper]{article}

\usepackage[french]{babel}
\usepackage[utf8] {inputenc}
\usepackage{soul}
\usepackage{color}

\definecolor{y}{RGB}{245, 255, 189}
\sethlcolor{y}

\begin{document}
  \hl{\'e} % works
  %\hl{é} % doesn't work
\end{document}
doncherry
  • 54,637
Zach
  • 653
  • 6
  • 10

3 Answers3

48

For UTF-8 input, use soulutf8; don't forget fontenc!

\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{soulutf8}
\usepackage{color}

\definecolor{y}{RGB}{245, 255, 189}
\sethlcolor{y}

\begin{document}

\hl{\'e}
\hl{é}

\end{document}

enter image description here

There is no 15pt option for article.

egreg
  • 1,121,712
  • 2
    Indeed, why do have soul and soulutf8 packages? Madness! – Pepe Mandioca Sep 07 '16 at 18:06
  • You could use the extsizes package and then use \documentclass[15pt]{extarticle}. I don't know about other compilers, but this is just fine in pdfLaTeX. – Someone Apr 14 '20 at 13:33
  • @Someone Yes, if one wants 15pt (there are some reasons one might want to), then extsizes is the proper way. My comment was about the OP's document. – egreg Apr 14 '20 at 13:35
7

use xelatex instead:

\documentclass[12pt , a4paper]{article}
\usepackage{fontspec}
\usepackage[french]{babel}
%\usepackage[utf8] {inputenc}
\usepackage{soul}
\usepackage{color}

\definecolor{y}{RGB}{245, 255, 19}
\sethlcolor{y}

\begin{document}
  \hl{\'e} % works
  \hl{é} % works
\end{document}
6

The soul package has its limitations. This one seems to be one of them.

You can let it work by putting accented characters in a \mbox:

\documentclass[a4paper]{article}

\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{soul}
\usepackage{color}

\definecolor{y}{RGB}{245, 255, 189}
\sethlcolor{y}

\begin{document}
  \hl{\'e} % works
  \hl{\mbox{é}} % works as well
\end{document} 

Output:

enter image description here

Otherwise you have to use XeLaTeX

\documentclass[a4paper]{article}

\usepackage[french]{babel}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{soul}
\usepackage{color}

\definecolor{y}{RGB}{245, 255, 189}
\sethlcolor{y}

\begin{document}
  \hl{\'e} % works
  \hl{é} % works as well
\end{document} 
karlkoeller
  • 124,410