fmarotta / kaobook

A LaTeX class for books, reports or theses based on https://github.com/kenohori/thesis and https://github.com/Tufte-LaTeX/tufte-latex.
https://github.com/fmarotta/kaobook
LaTeX Project Public License v1.3c
862 stars 186 forks source link

Using other languages with varioref #33

Closed TheoWinterhalter closed 4 years ago

TheoWinterhalter commented 4 years ago

The documentation of varioref states that it can be used together with babel to change the output language but babel has to be loaded first. Additionally, the language options have to be sent to varioref when loading it.

My current solution is to modify kaorefs with

\usepackage[french,english]{babel} % Load characters and hyphenation
\RequirePackage[french,english]{varioref}

And it seems to work, but it doesn't seem ideal. Maybe the language arguments should be passed on to the class?

fmarotta commented 4 years ago

I absolutely agree. In principle languages can be passed as options to the class, and, always in principle, they are in turn passed to all the packages. The problem was that in order for varioref to detect the changes in language, it needed to be loaded after babel. Thus, since I didn't want to load babel by default (someone may want to use polyglossia), the only way was to load the kaorefs package after loading bable, that is, to let the user load it in the main.tex. This is also how other kao-packages work, like kaobiblio. So, from now on, kaorefs is not loaded by default but the user, if he so chooses, can load it from the main.tex. Let me know if it now works for you.

fmarotta commented 4 years ago

So now the language options can be passed either at the class level, e.g.

\documentclass[french,english]{kaobook}

or directly to the kaorefs package, like so:

\usepackage[english,french]{kaorefs}
TheoWinterhalter commented 4 years ago

That sounds like a great way to deal with the problem! Thanks.

fmarotta commented 4 years ago

I forgot to mention that, while most captions are translated automatically thanks to babel, others are specific to the kaobook and require additional work. For instance, while in LaTeX there exists a \chaptername command (which is translated by babel), there is no \sectionname, so I define it (as "Section") in the kaorefs package. The problem is that it will not be tranlsated by babel, so the translations must be added to the kaorefs package as well. The same holds for other captions such as the one for short figure (Fig.), or those for mathematical environments (Theorem, and so on). So far I have added the translations only for English and Italian because these are the only languages that I know well enough, but if someone reading this issue is willing to contribute the translations for his or her language, all they have to do is editing the file styles/kaorefs.sty and add a block similar to the following:

\addto\captionsenglish{%
  \renewcommand{\chapternameshort}{Chap.}
  \renewcommand{\sectionname}{Section}
  \renewcommand{\sectionnameshort}{Sec.}
  \renewcommand{\subsectionname}{Subsection}
  \renewcommand{\subsectionnameshort}{Subsec.}
  \renewcommand{\figurenameshort}{Fig.}
  \renewcommand{\tablenameshort}{Tab.}
  \renewcommand{\eqname}{Equation}
  \renewcommand{\eqnameshort}{Eq.}
  \renewcommand{\defname}{Definition}
  \renewcommand{\thmname}{Theorem}
  \renewcommand{\propname}{Proposition}
  \renewcommand{\lemmaname}{Lemma}
  \renewcommand{\remarkname}{Remark}
  \renewcommand{\examplename}{Example}
  \renewcommand{\exercisename}{Exercise}
}