I develop a package that improves LaTeX support for the Latvian language. One of the things I have here is different style used for things like Chapter 1, Theorem 1.1 etc. First, the phrase is written using ordinal numbers. Second, there is an ordinal indicator in a form of a period. By these rules, Chapter 1 becomes 1. nodaļa, which literally means 1st chapter. Accordingly, in the package I have to:
- swap the name and the number in places like
- make the period appear everywhere where the number is printed or referenced, such as headings,
Of course, I want to support not only the standard classes, but also packages the user might load. I can see three ways how to do this:
Method 1: Redefine all relevant
\the… commands to contain the period, and also swap
\the… and text in appropriate places.
- This is not a universal solution — we add the
\the…commands to the list manually
- Per every new object type to be supported, up to two redefinitions may be needed — one for the number and one for the macro typesetting the heading/caption text
- When a number not ending with a digit is constructed by some third-party package, it might end up with a period in the middle (Figure 1.a), which is wrong. In general, if a
\the…macro we don't know about tries to use a
\the…macro we have redefined, the output may contain superfluous periods.
Method 2: Eliminate the first method's Con #1 and partially Con #2 by altering
\arabic instead of the
\the… macros. But this will produce a period in all places where
\arabic is used, meaning that there is a good chance to break something elsewhere.
Method 3: Do not change the number format directly, but rather add the period in places where the number is typeset, for example, figure/table captions,
- The number of places where the value of
\the…is output is largely limited, and packages usually don't introduce new ways to do it. This looks better than redefining all
- If, however, a package has a custom place where the number is typeset, then it's most likely the new heading (like
amsthmdefines a macro to output Theorem 1). But we need to swap the number and the text, thus we have to change the new heading anyway! When we do this, we might as well add the period. Therefore, now only one redefinition per package (more precisely, per object type) suffices.
- Since now
\numberlineand similar things have to add the period, they have to expand and analyze the number to tell if it ends with a digit (we shouldn't put a period after the number 1a).
- Not very semantic
Currently I have implemented method 3. But I don't particularly like the implementation. On the other hand, I also don't see any more convenient way to achieve the goal. So, the question: can the task specified in the first paragraph be done better than in the described solutions?