2

I have problems getting fancyref to properly work for German together with the fontspec/polyglossia set-up.

This is the bare set-up without any language settings:

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage{fancyref}

\begin{document}
Das ist ein deutscher Text
\begin{figure}
    \centering
    Das soll eine Abbildung sein
    \label{fig:sample}
    \caption{Beispiel-Abbildung}
\end{figure}

\pagebreak

Das ist die zweite Seite mit einem Verweis auf \fref{fig:sample}.
\end{document}

The interesting thing is and will be the result of the fref which refers to the figure "on the preceding page".

In this initial stage the figure is numbered as "Figure 1" and the reference reads "figure on the preceding page".

Adding

\usepackage{polyglossia}
\setmainlanguage{german}

will change the caption to "Abbildung 1" (which is correct) and the reference to "abbildung on the preceding page". Note the lowercase "a" in "abbildung", which is not correct, although it's notable that the reference uses the German word at all.

According to the fancyref manual this should be set to German with

\usepackage{german}
\usepackage[german]{fancyref}

However, this results a) in the error message "! You haven't defined the language [ yet." and b) the text "]german" to be included at the beginning of the document.

If I remove \setmainlanguage{german} the reference reads "figure auf der vorherigen Seite".

If I remove \usepackage{german} it reads "Abbildung on the preceding page"

I am completely confused about all this. What do I need for a German document with LuaLaTeX and fontspec and German fancyref references?

9
  • 3
    The package german is obsolete and should not be used in newer documents.
    – egreg
    Mar 1, 2019 at 15:25
  • This is what I suspected, especially given that fancyref's manual is from 1999. However, without it (at least with my attempts so far) fancyref will not use the German labels. It will translate "figure" with "Abbildung" but not "on the preceding page" (and all other reference texts).
    – uli_1973
    Mar 1, 2019 at 15:29
  • 3
    \usepackage[german]{babel}\usepackage[german]{fancyref} works (I would prefer babel anyway), but the problem is that fancyref doesn't have declarations for ngerman, so you would have to add them. Using some newer package as egreg suggested is certainly better. Mar 1, 2019 at 15:49
  • I thought that using babel together with fontspec was obsolete? That's obviously not true? However, I'll have a look at the newer package(s), even if that means to review >150 pages of an existing document.
    – uli_1973
    Mar 1, 2019 at 15:54
  • 3
    @uli_1973 - It is definitely not true that using babel together with fontspec is obsolete. Several years ago (5, maybe, and probably more), there was a phase when babel and luatex didn't get along. However, unless your TeX distribution is positively ancient, this should be no longer be of any concern.
    – Mico
    Mar 1, 2019 at 16:07

1 Answer 1

4

First thing: \label has to go after \caption.

The “proper” solution is to use the language option for fancyref:

\documentclass{scrartcl}

\usepackage{polyglossia}
\usepackage{fontspec}
\usepackage[german]{fancyref}

\setmainlanguage{german}

\begin{document}

Das ist ein deutscher Text
\begin{figure}
    \centering
    Das soll eine Abbildung sein
    \caption{Beispiel-Abbildung}
    \label{fig:sample}
\end{figure}

\pagebreak

Das ist die zweite Seite mit einem Verweis auf \fref{fig:sample}.

\end{document}

enter image description here

I'd use varioref and cleveref, though.

\documentclass{scrartcl}

\usepackage{polyglossia}
\usepackage{fontspec}
\usepackage[german]{varioref}
\usepackage[noabbrev]{cleveref}

\setmainlanguage{german}

\begin{document}

Das ist ein deutscher Text
\begin{figure}
    \centering
    Das soll eine Abbildung sein
    \caption{Beispiel-Abbildung}
    \label{fig:sample}
\end{figure}

\pagebreak

Das ist die zweite Seite mit einem Verweis auf \vref{fig:sample}.

\end{document}
7
  • > The “proper” solution is to use the language option for fancyref < This is indeed one of the things I tried. However, the deciding difference between my attempt and your solution is that you use \setmainlanguage after loading fancyref.
    – uli_1973
    Mar 1, 2019 at 15:52
  • What is the exact advantage of using varioref and cleveref in combination?
    – uli_1973
    Mar 1, 2019 at 15:53
  • 2
    @uli_1973 - I'd say that using varioref and cleveref has three main advantages over using fancyref. First, the packages are still maintained and updated regularly; fancyref was last updated in 1999. Second, the varioref and cleveref packages know lots of cross-referenceable objects; the fancyref package only knows about 7 types (chap, sec, eq, fig, tab, enum, and fn) by default. Third, it's not essential (though it doesn't hurt either...) to use the fig: prefix for figure labels, the tab: prefix for table labels, the eq: prefix for equation labels, etc.
    – Mico
    Mar 1, 2019 at 16:04
  • Thank you, but again: what's the reason to use both packages? Shouldn't I then simply use cleveref?
    – uli_1973
    Mar 3, 2019 at 9:28
  • @uli_1973 varioref implements the phrases “in the next page” and so on.
    – egreg
    Mar 3, 2019 at 9:51

You must log in to answer this question.

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