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.

Many packages come with switches, to be defined in the preamble. Is it possible to hit such a switch also in the body of the document?

Example: Can I switch from the functionality of

\usepackage[russian]{babel}  

to that of

\usepackage[french]{babel}  

within one section or figure caption?

Edit: babel is just one example for which I have a good idea about what the switches actually do, but the question is meant to be more general. By the way, is there a generic name for these switches that could be used, e.g., to search the documentation of a package? Or a term for cases when both options can be used in parallel (like in babel) or not?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

babel is perhaps not the best example, because you could state both options and switch by \selectlanguage:

\usepackage[russian,french]{babel}
...
\selectlanguage{french}
...
\selectlanguage{russian}

Many packages provide their own way to change options aka switches: hyperref uses \hypersetup, caption uses \captionsetup, even classes offer such late configuration like KOMA-Script classes by \KOMAoption and \KOMAoptions.

share|improve this answer
    
With hindsight, I agree that babel was not the best example - it is just one of the packages that I am a bit familiar with, which helped in phrasing the question (which I have edited by now to reflect its more general nature). Special thanks for pointing out that classes do it too! –  Daniel Mietchen Aug 5 '10 at 22:23

If you specifically mean babel, then you load the package with both languages

\usepackage[russian,french]{babel}

then switch with \selectlanguage{russian} (In the example, french will be the main language.) See the babel documentation for more detail.

(Other packages with load time options also provide methods to alter settings, but this is package-dependent.)

share|improve this answer
    
I had hoped (dreamed?) there were a package-independent function but thanks for putting me back into reality. I am not specifically after babel and have clarified this in my question. –  Daniel Mietchen Aug 5 '10 at 22:16
1  
Nope- it usually requires the package author to provide a command like \pkgnamesetup{key=value} that will toggle the options. Most do, some dont, and everyone needs to use a different name to avoid clashes. –  Sharpie Aug 5 '10 at 22:50
1  
It all depends what the load-time options do. Some simply set 'dynamic' values, and can therefore be altered during the run. Others make once-only changes to behaviour. For example, if you have stuff that needs to happen in the preamble then the option would not make sense in the document body. –  Joseph Wright Aug 6 '10 at 5:43

For Babel, you have the command \selectlanguage that does exactly that. Obviously, you need such a thing to switch language inside a document body, because it wouldn't make sense to select all the languages at the same time! As you probably know, the convention in Babel is that the last language in the list of option is activated at \begin{document}; hence a command like \usepackage[french,russian]{babel} will declare the document to be in Russian by default, and use the settings of russian.ldf.

Generally speaking, any package you use should provide such switches because that's exactly what you need, as a user. If the functionality of the package implies that you can switch between different options, the developer has probably foreseen such use, and it should be mentioned in the documentation.

But you can't load a package mid-document (\usepackage forbids that). This is a technical limitation that has its justification from the point of view of an interface designer. It is a guarantee to both the user and the developer: if someone writes a package for LaTeX, he knows that it will be loaded before \begin{document}, and hence before any text will be output to the page; this means he will be able to make implementation choices depending on this (that might fail if this condition wasn't true). If you were, as a user, to modify \usepackage's behaviour so that it could be invoked after the preamble—it shouldn't be too hard, by tweaking the LaTeX sources—, and you used that new possibility, you could unknowingly be in a situation that hasn't been foreseen at all by the developer, because it's impossible given the way LaTeX is currently written (and this is a design choice, not a technical problem). Hence you, the user, depend on the user interface the package developer has programmed for you; just like the package developer depends on the programming interface the LaTeX core provides.

Of course, loading a package mid-document (with or without different switches) could be completely harmless in many cases, but this is not something you can rely on; the only guarantee the user has are the switches the package developer has provided himself.

Sorry I can't think of any concrete example right now.

share|improve this answer
    
Thank you too. Yes, noticing that the last language is used in babel was easy. But I was after a package-independent approach and have clarified that in the question. –  Daniel Mietchen Aug 5 '10 at 22:20
    
I've seen your edit, and edited my answer accordingly. –  Arthur Reutenauer Aug 5 '10 at 23:10

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.