Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 \@makechapterhead and \@part;
  • make the period appear everywhere where the number is printed or referenced, such as headings, \ref-s etc.

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.

Cons:

  • 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, \@seccntformat, \ref, \numberline.

Pros:

  • 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 \the… commands.
  • If, however, a package has a custom place where the number is typeset, then it's most likely the new heading (like amsthm defines 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.

Cons:

  • Since now \ref, \numberline and 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?

share|improve this question
2  
Method 2 should really be avoided. \arabic should really just return Arabic numbers. –  Martin Scharrer Jul 13 '11 at 8:54
2  
It seems to me that Hungarian has similar problems; I suggest you to have a look at magyar.ldf of the babel package. There is also a different version that in TeX Live resides in texmf-dist/doc/latex/magyar –  egreg Jul 21 '11 at 18:41
    
@egreg: Thanks! babel uses the same (third) solution as I do now. Now I have more confidence that it's the (though not very pretty) way to go. –  Andrey Vihrov Jul 22 '11 at 6:58

1 Answer 1

It seems that what you want to do is to change the number format from \arabic to \latord where \latord outputs a Latvian-style ordinal number when given a counter as input. From a semantic point of view, the best way to do this would be to change the relevant \the... commands as per your suggestion 1.

That is, you could do it the other ways (although bear in mind Martin's warning about redefining \arabic), but it's clearer for someone else reading your code what you are doing if you do directly what you are trying to do...

A number of packages might give you some clues as to how to build a \latord like macro:

  • fmtcount is quite sophisticated and includes several language options
  • nth is much simpler
  • engord more sophisticated than nth but without the language support of fmtcount

There aren't really that many \the... commands to redefine, and packages like titlesec can help automate some of the redefinitions...

share|improve this answer
1  
One of the things I'm worried about the most in this approach is that when a \the… macro unknown to me uses one of the redefined control sequences (like \thesubsection uses \thesection), the output will be incorrect. This, along with that there are two places to make changes for each counter, made me choose the alternative, non-semantic way when I was first writing it. Generally, I'd prefer the programmatically easiest way here, because the purpose of the code can always be explained in the comments in the .dtx file. –  Andrey Vihrov Jul 13 '11 at 13:45
    
@Andrey Have you had a look at titlesec to change all the \thesection-like macros in a relatively straightforward way? –  Seamus Jul 13 '11 at 14:50
    
Sure, this is the way to go if redefining all \the… stuff. Though it only applies to a fixed part of all cases (think, for example, numbers in floats and theorems). –  Andrey Vihrov Jul 13 '11 at 15:08
    
@Andrey I'm sure amsthm or ntheorem can help with theorem-like environments and I bet there are packages to make floats easier to deal with as well... I can't see there being a properly "general"... –  Seamus Jul 13 '11 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.