Skip to content

Commit

Permalink
Enable code listings translations
Browse files Browse the repository at this point in the history
Float captions, list of code and cleveref referencing now support all languages
  • Loading branch information
alexpovel committed Feb 4, 2021
1 parent d4a42ce commit 6148d55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
16 changes: 16 additions & 0 deletions cookbook.cls
Expand Up @@ -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,
Expand Down Expand Up @@ -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 <type> 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
Expand Down
14 changes: 8 additions & 6 deletions lib/translations.tex
Expand Up @@ -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}
Expand Down

0 comments on commit 6148d55

Please sign in to comment.