8

Is it possible to write out the referenced chapter number?

Instead of

I’m referencing Chapter 1, „Referencing“

I would like to see

I’m referencing Chapter one, „Referencing“.

MWE:

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{hyperref}

\begin{document}

\chapter{Referencing}
\label{cha:referencing}

I'm referencing Chapter~\ref{cha:referencing},~\enquote{\nameref{cha:referencing}}

\end{document}
7

Use cleveref together with fmtcount:

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{fmtcount}
\usepackage{hyperref}
\usepackage{cleveref}

\crefformat{chapter}{\chaptername~#2\numberstringnum{#1}#3}

\begin{document}

\chapter{Referenzieren}
\label{cha:referencing}

Dies ist ein Verweis auf \cref{cha:referencing}.

\end{document}

Blame Google if the German is bad.

enter image description here

If you want that also “Kapitel” is in the hyperlink, change the \crefformat line into

\crefformat{chapter}{#2\chaptername~\numberstringnum{#1}#3}

and if you want the number name to begin with a capital letter, use \Numberstringnum.

  • Google is right in this case. But as a German I would say that the verbal expression of the number should be uppercase, i.e. Eins – user31729 Jul 8 '15 at 17:15
  • 1
    @ChristianHupfer Thanks for the help on language. I added the necessary change to make. – egreg Jul 8 '15 at 17:18
  • No problem. I think the style of eins or Eins depends on the context anyway, your solution was correct in the sense of German language anyway. – user31729 Jul 8 '15 at 18:02
  • If I use this (for English, not German), I get "CHAPTER three" rather than "Chapter three". – retorquere Apr 28 '16 at 14:49
  • @retorquere Please, open a new question, with a reference to this one, with a minimal example. – egreg Apr 28 '16 at 16:39
6

Yes, this is possible, but it's necessary to extract the chapter number first before it can be used. \ref... does not provide a number at all, so refcount and its getrefnumber comes into action. This will produce 1 here.

To get a verbal expression of 1 as Eins here, use \Numberstringnum or \numberstringnum for eins from fmtcount package.

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{refcount}
\usepackage{fmtcount}
\usepackage{hyperref}

\begin{document}

\chapter{Hallo Welt}
I'm referencing Chapter~\Numberstringnum{\getrefnumber{cha:referencing}},~\enquote{\nameref{cha:referencing}}

\chapter{Referencing}
\label{cha:referencing}


\end{document}

enter image description here

  • The mixing of languages is a little bit weird ;-) – user31729 Jul 8 '15 at 17:09
  • You could even use cleveref's command \Cref{...} to get Chapter automatically – user31729 Jul 8 '15 at 17:11
  • Thank you very much! I accept @egreg's answer because I like the cref style, however you've been very helpful. :-) – sqe Jul 8 '15 at 17:29
0

I wrote a little macro to deal with german cardinals and ordinals in a proper way. For the latter, \Ordinalstringnum and \ordinalstringnum from fmtcount can't be used effectively, as they only give the strong form (e.g. "erster", which is quite useless if you want to print "erstes Kapitel", "das erste Kapitel" etc.). Here's the code with some example output:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{refcount,fmtcount}

\newcommand{\refzw}[2][o]{%
\def\refnum{\getrefnumber{#2}}%
\lowercase{\ifnum\ifx#1}o\ifnum\refnum=1 1\else\ifnum\refnum=3 1\else\ifnum\refnum=7 1\else\ifnum\refnum=8 1\else0\fi\fi\fi\fi\else0\fi=1%
\ifnum\refnum=1\def\zw{ers}\def\zwg{Ers}\fi%
\ifnum\refnum=3\def\zw{drit}\def\zwg{Drit}\fi%
\ifnum\refnum=7\def\zw{sieb}\def\zwg{Sieb}\fi%
\ifnum\refnum=8\def\zw{ach}\def\zwg{Ach}\fi%
\else\def\zwg{\Numberstringnum{\refnum}}\def\zw{\numberstringnum{\refnum}}    \fi%
\if1\ifx#1O1\else\ifx#1K1\else0\fi\fi\zwg\else\zw\fi%
\ifnum\refnum>19\lowercase{\ifx#1o{s}\fi}\fi%
}

\begin{document}
\section{Einleitung}\label{einl}
\refzw[O]{einl}tens steht das \refzw{einl}te Kapitel in Kapitel \refzw[k]{einl} – oder schreibt man Kapitel \refzw[K]{einl}? Dann gibts aber noch ein \refzw{haupt1}tes und ein \refzw{haupt2}tes Kapitel, aber kein dreites. Dann kommen die Kapitel \refzw[K]{haupt3} und \refzw[K]{haupt4}.
\section{Hauptteil}\label{haupt1}
\section{Fazit}\label{haupt2}
\section{Schluss}\label{haupt3}
\section{jetzt}\label{haupt4}
\end{document}

output

The command takes the reference key as a mandatory and one of the following options as an optional argument:

  • o (default) prints ordinal number, e.g. "ers"
  • O prints capitalized ordinal number, e.g. "Ers"
  • k prints cardinal number, e.g. "eins"
  • K prints capitalized cardinal number, e.g. "Eins"

As you may have noticed, the ordinal numbers are printed without any endings, you have to write e.g. "im \refzw{key}ten Kapitel" for it to output "im ersten Kapitel". The macro works with \section headlines in articles as well as \chapter in books and prints correct numbers until 100. It needs the following packages:

\usepackage[ngerman]{fmtcount}
\usepackage{refcount}

or

\usepackage[ngerman]{babel}
\usepackage{refcount,fmtcount}

fmtcount by the way may need to be updated, an older version (which came with Ubuntu 14.04's TexLive) wrongly printed "einsundzwanzig".

Print out long version

If you want it to print out "erste" instead of "ers" (so just to add "n", "s" etc.), replace the } at the end by:

\lowercase{\ifx#1}ote\fi%
}
  • Btw, correct german would be "Kapitel eins", not capitalizing the numeral (see Duden and canoonet). I apologize for doing it wrong in the above example! – dessert Mar 16 '16 at 9:29
  • you can always edit your post… – mirabilos Mar 24 '16 at 19:10
  • 1
    I perceive this as a matter of style and therefore the duden directions not binding in this case. Besides, it would destroy my neat example. ;) – dessert Mar 25 '16 at 6:51

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.