From 6148d55db8d28bece0da257e5e67218488f72147 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Thu, 4 Feb 2021 17:44:23 +0100 Subject: [PATCH] Enable code listings translations Float captions, list of code and cleveref referencing now support all languages --- cookbook.cls | 16 ++++++++++++++++ lib/translations.tex | 14 ++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cookbook.cls b/cookbook.cls index fcad808..4f7c0da 100644 --- a/cookbook.cls +++ b/cookbook.cls @@ -226,6 +226,13 @@ fontsize=auto,% Reset to surrounding font size so its fits into the text flow } +% Set up the floating environment, e.g. what is says in the caption of floats: +\SetupFloatingEnvironment{listing}{% Requires `newfloat` usage + name=\TransListing{}, + listname=\TransListOfListings{}, +} +% Setup for referencing the floats correctly is done in `cleveref` settings! + % In code environments, to be able to copy from the PDF (despite that not being a good % idea usually), we want the line numbers to not be part of the selection. % This command prints them, but renders the actual copied content empty, @@ -2207,6 +2214,15 @@ \Crefname{chemreac}{\TransReaction{}}{\TransReactions{}} \creflabelformat{chemreac}{#2\textbf{R}#1#3}% No (1), but 1, aka remove parentheses + % Code listings, see `minted` package. + % Introduce a new called `code`, then make the (existing) counter `listing` + % use it by aliasing. Modifying `listing` directly with `\crefname{listing}...` + % did not work! See also + % https://tex.stackexchange.com/a/310355/120853 + \crefname{code}{\TransListing{}}{\TransListings{}} + \Crefname{code}{\TransListing{}}{\TransListings{}} + \crefalias{listing}{code} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Color Boxes diff --git a/lib/translations.tex b/lib/translations.tex index 6db7d60..4c7ff30 100644 --- a/lib/translations.tex +++ b/lib/translations.tex @@ -143,12 +143,14 @@ \providecaptionname{english}{\TransListOfIllustrations}{List of Illustrations} \providecaptionname{german}{\TransListOfIllustrations}{Illustrationsverzeichnis} -% Instead of providing a translation \Trans command here, just override commands -% from listings package directly -\providecaptionname{english}{\lstlistingname}{Code Listing} -\providecaptionname{german}{\lstlistingname}{Code} -\providecaptionname{english}{\lstlistlistingname}{List of Code} -\providecaptionname{german}{\lstlistlistingname}{Codeverzeichnis} +\providecaptionname{english}{\TransListing}{Code Listing} +\providecaptionname{english}{\TransListings}{Code Listings}% Plural for cleveref + +\providecaptionname{german}{\TransListing}{Code} +\providecaptionname{german}{\TransListings}{Codes}% Plural for cleveref + +\providecaptionname{english}{\TransListOfListings}{List of Code} +\providecaptionname{german}{\TransListOfListings}{Codeverzeichnis} \providecaptionname{english}{\TransListOfExamples}{List of Examples} \providecaptionname{german}{\TransListOfExamples}{Beispielverzeichnis}