7

I'd like to know how to include words with accents in \label{} and \ref{} arguments.

For example : \label{Molécules d'immunoglobulines} \ref{Molécules d'immunoglobulines}

I've already succeeded giving file names with spaces and accents to the argument command \includegraphics{} thanks to the package grffile, but I can't find an easy way to do it with \label{} and \ref{} commands. Do you have any idea ?

Thanks.

3
  • 3
    It is best to consider that argument to be the same as a tex command and use the same syntax restrictions just a-zA-Z0-9 and ascii punctuation. It is possible to make more work but it adds no extra functionality and is rather fragile Aug 23, 2015 at 8:20
  • 1
    @DavidCarlisle - It may be worth pointing out that the "a-zA-Z0-9 and ascii punctuation" restriction applies to pdfLaTeX (and even older engines/formats). XeLaTeX and LuaLaTeX are not affected by this restriction.
    – Mico
    Aug 23, 2015 at 8:43
  • @Mico they do work, but I think as a matter of definition of latex as a language that doesn't mean that they are valid and should be used. Aug 23, 2015 at 9:03

1 Answer 1

9

The key for \label and \ref consists of ASCII letters, digits, and punctuation (LaTeX Companion, 2ed).

Package babel does some hacking to allow its shorthands.

The key is internally used to create a command \r@<key> via \csname. This can be broken by anything, which is not a character or does not expand to a letter. Accented letters quite often breaks this, depending on their implementation (packages inputenc, fontenc), examples:

  • Font encoding OT1 (default in LaTeX2e) does not have slots for the accented characters, thus is implementation uses the \accent primitive, which cannot be used in \csname.

  • The font encoding T1 has slots, thus it might work, e.g.:

    \documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \begin{document}
    \section{Hello World}
    \label{Molécules d'immunoglobulines}
    \ref{Molécules d'immunoglobulines}
    \end{document}
    

    The .aux file contains:

    \newlabel{Mol\IeC {\'e}cules d'immunoglobulines}{{1}{1}}
    

    The simple example works with this for of the accented letter, but there is no grantee that this works with all packages.

  • Best for accented characters are LuaLaTeX or XeLaTeX, when the accented characters are also ordinary letters at TeX level, because these TeX engines are capable of Unicode.

1
  • 1
    +1 for mentioning that accented characters are no big deal when working with XeLaTeX and/or LuaLaTeX.
    – Mico
    Aug 23, 2015 at 8:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .