0

I'm having some problems on creating a class that changes the word "Definition" in \begin{definition} according to a chosen language. For simplicity I will consider only the English language

The class file myreport.cls

\NeedsTeXFormat{LaTeX2e}

\ProvidesClass{myreport}

\RequirePackage{changelang}

\DeclareOption{eng}{
  \PassOptionsToPackage{\CurrentOption}{changelang}
}

\ProcessOptions\relax

\LoadClass[12pt, a4paper, twoside, notitlepage]{extreport} 

\endinput

The file changelang.sty

\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{changelang}

\RequirePackage{amsmath, amssymb, amsthm} 

\RequirePackage[T1]{fontenc} % output

%% language options
\DeclareOption{eng}{
    \theoremstyle{definition}
    \newtheorem{definition}{Definition}[section]
    \providecommand*{\definitionautorefname}{Definition}    
}

\ProcessOptions\relax

\endinput

Now when I try to use \begin{definition} in the main document after choosing \documentclass[eng]{myreport}, I get the complaint that it's undefined. Any ideas on how to correct that?

Thanks in advance.

11
  • 1
    You use \newtheorem{defi}, therefore you should use \begin{defi} and not \begin{definition}. Also the MWE doesn't work because you load the extreport class after the changelang package, therefore when you load the package the section counter is not defined yet, resulting in an error.
    – Marijn
    May 1, 2022 at 6:02
  • @Marijn Thanks for the correction. That was a typo. Regarding your second point. I've tried loading it before processing the options in the cls file and also in the sty file. No luck yet. begin{definition} still undefined. Any ideas?
    – user40276
    May 1, 2022 at 6:47
  • Are you sure this is the first error you get, or are there any other errors before? Set your editor or terminal command to halt-on-error to make sure LaTeX stops at the very first error that is encountered. I tested your MWE and by loading the extreport class directly after \ProvidesClass{myreport} and fixing the typo for definition it worked without a problem.
    – Marijn
    May 1, 2022 at 6:54
  • 1
    you don't (normally) want to declare the whole environment in the option handler, all the standard fixed texts use a \...name convention so declare your environment using \definitionname rather than Definition then define \definitionname to be Definition with language options giving suitable translations. see \chaptername, \contentsname, \figurename etc May 1, 2022 at 7:31
  • 1
    you can declare a new environment in the option handler it is just rather unusual to do so, and a major part of the design of latex2e (over the previous latex2.09) was to pull all fixed strings out to simple \xxxname macros so that language customisation would not need to re-do complicated layout definitions, and simply supply localised versions of the strings May 1, 2022 at 20:48

0

You must log in to answer this question.

Browse other questions tagged .