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'm creating a mystyle.sty package that sets backgrounds, styles and an introduction. The main .tex file only contains few package loading and options, and of course the main text. One of the options is

\setdefaultlanguage{finnish}

What I need is that the introduction part (in the package) would change to e.g. english should I change the default language to english too. So the question is:

  1. If possible, how do I detect the language that is set by the command \setdefaultlanguage?
  2. Which would be the simplest way to use this information to choose the appropriate intro?

For the second question, the introtext commands are stored to, say, \introinfinnish and \introinenglish. Number of different languages are not restricted to two.

A minimal XeLaTeX example (main.tex):

\documentclass[12pt,a4paper]{memoir}

\usepackage{fontspec}

\usepackage{polyglossia}
\setdefaultlanguage{finnish} % (english)
\setotherlanguage{english}

\usepackage{mystyle}

\begin{document}
  \intropage % from mystyle
  \clearpage

  Something in finnish % (english)
\end{document}

and the package (mystyle.sty)

\ProvidesPackage{mystyle}
\newcommand{\introinfinnish}{Text in finnish...}
\newcommand{\introinenglish}{Text in english...}

% some commands that selects the correct introtext and stores it into \introtext

\newcommand{\intropage}{ % just a sketch
  \@date
  \vfill
  \introtext
}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

The main language is stored in \xpg@main@language, so something like the following will do.

\ProvidesPackage{mystyle}
\newcommand{\introinfinnish}{Text in finnish...}
\newcommand{\introinenglish}{Text in english...}

% some commands that selects the correct introtext and stores it into \introtext

\newcommand{\intropage}{% just a sketch
  \@date
  \vfill
  \@ifundefined{introin\xpg@main@language}
    {\PackageWarningNoLine{mystyle}{No introduction for `\xpg@main@language'}%
     \introinenglish}
    {\@nameuse{introin\xpg@main@language}}
}

As you see, you can use any language you wish, provided you give a definition fo \introin<language>.

Please, use \setmainlanguage rather than the deprecated \setdefaultlanguage

share|improve this answer
    
Very nice and simple solution! Including new intro texts with other languages couldn't be anymore simple. And thanks for the hint on using \setmainlanguage. –  TKO Jun 18 '13 at 8:35

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.