2

I want to create a document class for my university department, it is supposed to serve as a template for students' bachelor and master theses. These theses must be written in Russian (or, in extremely rare occasions, in English). So, my class has to generate some boilerplate text in Russian like the university name, the faculty name, etc.

Currently, I have the following lines in my class file:

\RequirePackage[T2A]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage{csquotes} % since babel insists on it.
\RequirePackage[english,russian]{babel}

but I feel that I should really avoid using these packages in a document class. Is there a way I can typeset several captions in Russian without loading inputenc, fontenc and babel?

  • Yes, you can include those items in the document class. Do it. I have a document class (distributed via CTAN) that pre-configures fonts and everything else. If the user wants something different, it can be changed. But the user does not have to change anything. – user139954 Apr 16 '18 at 15:42
  • It seems you have very strict requirements and it's not at all a bad idea to enforce them in the class. – egreg Apr 16 '18 at 17:24
  • 2
    Unless you want to force people to use pdfLaTeX (rather than have the option of XeLaTeX or LuaLaTeX) you should probably at least use the if...engine packages (ifpdf, etc.) to use font packages that are compatible with the engine. – Alan Munn Apr 16 '18 at 18:20
  • @RobtAll Your use case is quite different, however. So as a blanket recommendation it's not without its problems. – Alan Munn Apr 16 '18 at 18:31
  • 1
    It is bad idea to include \RequirePackage[..]{babel} and similar commands into a documents class. This restricts scope of the class. Suppose, a person want to include references in French. Explicit \usepackage[french,english,russian]{babel} in the preamble of user document then will lead to the clash of options error which is difficult to locate. – Igor Kotelnikov Apr 17 '18 at 9:39
1

Given the situation, you might try something like this:

Create a document class option usermode (or pick something that will be understood).

Use \newif \if@usermode early in the class file. Then, if the user chooses [usermode] document class option, set \@usermodetrue.

Then the class file will decide what to do:

\if@usermode
  \typeout{Reminder: You selected usermode document class option. %
  This requires you to specify encodings, and other packages. %
  Did you read the instructions?}
\else
  \RequirePackage[T2A]{fontenc} % and the others
\fi

The reminder message merely types to the log file. Possibly useful, if a student did not read instructions, and complains to you.

Now, there is a potential problem. If the document class loads other packages, you may need to load the required packages first. Then, you could not wait for the student to write the packages in preamble. They would need to go prior to \documentclass.

You could also try using \@ifpackageloaded to test whether or not the student already loaded inputenc and the others. Then, supply any missing packages.

AFTERTHOUGHT: Have you considered using LuaLaTeX or XeTeX? These compilers always use utf-8 encoding, with the fontspec package. So you do not specify inputenc or fontenc. You can use Open Type fonts.

  • 1
    Right now I'm thinking about rolling out XeTeX/LuaTeX support first and see if anything beyond that would actually be required in practice. Polyglossia seems a nice replacement for Babel. – firegurafiku Apr 16 '18 at 22:43
2

In general, unless it's absolutely crucial, it's best not to add font encoding or input encoding packages to to a class file. I would certainly not load inputenc, but let users decide their own encoding.

If you do feel the need to add font encoding information (although I wouldn't) you should do this sensibly by checking which engine is being used. See e.g.

As for babel vs, polyglossia, it would depend very much on how good the Russian support is for polyglossia. babel now has support for the UTF-8 engines, so for many languages it's completely fine to use babel, and for some polyglossia support may be weak. This is another thing I would leave up to the user.

I would let the document class define the formatting, and then provide one or two sample template files which users can model their own documents on. These files would include the relevant font/encoding/language packages in them.

A lot of the decisions you make will depend on the kind of user base you have, and how well you can anticipate the kinds of things they might need to do. I maintain a thesis class for my university, and I would absolutely not add such packages to the class file, since the user base is extremely broad in its needs, and there's no way for me to anticipate them. If your case is similar you might want to do the same thing.

One other thing to keep in mind is where your users will get their information from. Although you might think that they will get it from your documentation, you'd be wrong: they'll get bits and pieces from all over the web, so if you force people into a particular engine like LuaTeX, for example, they may not even know such an engine exists much less how to tell their IDE to use it. So locking people into choices they didn't make isn't always what's best for them, even if it seems on the surface simpler.

  • Can you please share a link to your university thesis class? – firegurafiku Apr 17 '18 at 8:17
  • @firegurafiku It's msu-thesis on CTAN. – Alan Munn Apr 17 '18 at 10:55

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.