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?

uli_1973
  • 1,920
  • 3
    The package german is obsolete and should not be used in newer documents. – egreg Mar 01 '19 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 01 '19 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. – Ulrike Fischer Mar 01 '19 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 01 '19 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 01 '19 at 16:07
  • So what would be the arguments for using babel vs. polyglossia nowadays. Using luatex and fontspec is a prerequisite but the others not. I'm using not the latest TeXLive but that from my distro, which is LuaTeX, Version 1.0.4 (TeX Live 2017/Debian), so rather current. – uli_1973 Mar 01 '19 at 16:43
  • polyglossia development has stalled recently (https://github.com/reutenauer/polyglossia/issues) there was a maintenance release for TeX live 2018 that included outstanding pull requests, but there has not been any real activity by the maintainer to fix other bugs or enhance features since 2016. babel development picked up speed again a while ago and even if the current maintainer has to leave it, the package is so important that it will probably have to be maintained by some emergency committee if that happens. Many packages that need localisation features work together well with babel – moewe Mar 02 '19 at 06:15
  • ... but might have issues with polyglossia (especially the variant detection with polyglossia is tricky). If you stick to Western European languages (certainly German, English, French, ...) babel is IMHO certainly preferable to polyglossia. If you need complicated RTL scripts polyglossia might have a bit of an advantage still, but babel is trying to bridge that gap. Unfortunately our standard answer https://tex.stackexchange.com/q/88481/35864 might be a bit behind current developments. – moewe Mar 02 '19 at 06:19
  • Thank you for the elaboration. So can I assume that the deficiencies of babel regarding UTF-8 input that are mentioned in the "standard answer" and comments in 2012 and 2015 have become obsolete by now? I'm reviewing the infrastructure (originally put together in 2013 when I was starting with LaTeX) for a thesis and want to do things right now (to the extent this is possible ;-) ). – uli_1973 Mar 03 '19 at 08:58

1 Answers1

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}
egreg
  • 1,121,712
  • 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 01 '19 at 15:52
  • What is the exact advantage of using varioref and cleveref in combination? – uli_1973 Mar 01 '19 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 01 '19 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 03 '19 at 09:28
  • @uli_1973 varioref implements the phrases “in the next page” and so on. – egreg Mar 03 '19 at 09:51
  • @egreg so cleveref alone does not have these phrases, or implicitly requires varioref? – uli_1973 Mar 03 '19 at 10:58
  • @uli_1973 If varioref is loaded, then \cleveref changes \vref to be as you see in the printout. – egreg Mar 03 '19 at 11:01