\begin_inset Flex CharStyle:Code
status collapsed
+\begin_layout Plain Layout
+I18NPreamble
+\end_layout
+
+\end_inset
+
+ Language dependent information to be included in the LaTeX preamble when
+ this style is used.
+ Note that this will completely override any prior
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+I18NPreamble
+\end_layout
+
+\end_inset
+
+ declarations.
+ Must end with
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+EndI18NPreamble
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+.
+ The contents of this tag will occur once in the LaTeX preamble for each
+ language used by the document.
+ Each time, the following substitutions are made:
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+$$lang
+\end_layout
+
+\end_inset
+
+ is replaced by the language name (as used by the babel package).
+\end_layout
+
+\begin_layout Itemize
+The
+\begin_inset Quotes eld
+\end_inset
+
+Function
+\begin_inset Quotes erd
+\end_inset
+
+
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+_()
+\end_layout
+
+\end_inset
+
+ replaces its argument by the translation of the argument to the current
+ language.
+\end_layout
+
+\begin_layout Standard
+If the style defines text that appears in the typeset document, it may use
+
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+I18NPreamble
+\end_layout
+
+\end_inset
+
+ to support non-english and even multilanguage documents correctly.
+ The following excerpt (from the
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+theorems-ams.inc
+\end_layout
+
+\end_inset
+
+ file) shows how this works:
+\end_layout
+
+\begin_layout LyX-Code
+Preamble
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+providecommand{
+\backslash
+claimname}{Claim}
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+theoremstyle{remark}
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+newtheorem{claim}[thm]{
+\backslash
+protect
+\backslash
+claimname}
+\end_layout
+
+\begin_layout LyX-Code
+EndPreamble
+\end_layout
+
+\begin_layout LyX-Code
+I18nPreamble
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+AtBeginDocument{
+\backslash
+ifx
+\backslash
+LdfInit
+\backslash
+undefined
+\backslash
+relax
+\backslash
+else%
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+addto
+\backslash
+captions$$lang{
+\backslash
+renewcommand{
+\backslash
+claimname}{_(Claim)}}%
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+fi}
+\end_layout
+
+\begin_layout LyX-Code
+EndI18nPreamble
+\end_layout
+
+\begin_layout Standard
+The key to correct translation of the user visible text is the definition
+ of the command
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+claimname
+\end_layout
+
+\end_inset
+
+ in the standard preamble.
+ This command holds the name of the theorem that will appear in the output.
+ The
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+I18NPreamble
+\end_layout
+
+\end_inset
+
+ then uses the commands offered by the babel package to redefine
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+claimname
+\end_layout
+
+\end_inset
+
+ for each used language.
+ The
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+ifx
+\backslash
+LdfInit
+\end_layout
+
+\end_inset
+
+ test ensures that no LaTeX error occurs in documents that do not use babel.
+ Since LyX loads babel after the style-specific preamble, the whole command
+ is deferred to the actual start of the document with
+\begin_inset Flex CharStyle:Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+AtBeginDocument
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\end_deeper
+\begin_layout Description
+\begin_inset Flex CharStyle:Code
+status collapsed
+
\begin_layout Plain Layout
InnerTag
\end_layout
# - Proof
# - Case (regular only -- defined as an enumeration)
-Format 11
+Format 12
Style Theorem
Category Theorem
Series Bold
EndFont
Preamble
+ \providecommand{\theoremname}{Theorem}
\theoremstyle{plain}
- \newtheorem{thm}{Theorem}
+ \newtheorem{thm}{\protect\theoremname}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}\fi}
+ EndI18nPreamble
Requires amsthm
End
LatexName cor
LabelString "Corollary \thetheorem."
Preamble
+ \providecommand{\corollaryname}{Corollary}
\theoremstyle{plain}
- \newtheorem{cor}[thm]{Corollary}
+ \newtheorem{cor}[thm]{\protect\corollaryname}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}\fi}
+ EndI18nPreamble
End
LatexName lem
LabelString "Lemma \thetheorem."
Preamble
+ \providecommand{\lemmaname}{Lemma}
\theoremstyle{plain}
- \newtheorem{lem}[thm]{Lemma}
+ \newtheorem{lem}[thm]{\protect\lemmaname}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}\fi}
+ EndI18nPreamble
End
LatexName prop
LabelString "Proposition \thetheorem."
Preamble
+ \providecommand{\propositionname}{Proposition}
\theoremstyle{plain}
- \newtheorem{prop}[thm]{Proposition}
+ \newtheorem{prop}[thm]{\protect\propositionname}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}\fi}
+ EndI18nPreamble
End
LatexName conjecture
LabelString "Conjecture \thetheorem."
Preamble
+ \providecommand{\conjecturename}{Conjecture}
\theoremstyle{plain}
- \newtheorem{conjecture}[thm]{Conjecture}
+ \newtheorem{conjecture}[thm]{\protect\conjecturename}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}\fi}
+ EndI18nPreamble
End
LatexName fact
LabelString "Fact \thetheorem."
Preamble
+ \providecommand{\factname}{Fact}
\theoremstyle{plain}
- \newtheorem{fact}[thm]{Fact}
+ \newtheorem{fact}[thm]{\protect\factname}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}\fi}
+ EndI18nPreamble
End
Series Bold
EndFont
Preamble
+ \providecommand{\definitionname}{Definition}
\theoremstyle{definition}
- \newtheorem{defn}[thm]{Definition}
+ \newtheorem{defn}[thm]{\protect\definitionname}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}\fi}
+ EndI18nPreamble
End
LatexName example
LabelString "Example \thetheorem."
Preamble
- \theoremstyle{definition}
- \newtheorem{example}[thm]{Example}
+ \providecommand{\examplename}{Example}
+ \theoremstyle{definition}
+ \newtheorem{example}[thm]{\protect\examplename}
EndPreamble
- Requires amsthm
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\examplename}{_(Example)}}\fi}
+ EndI18nPreamble
End
LatexName problem
LabelString "Problem \thetheorem."
Preamble
+ \providecommand{\problemname}{Problem}
\theoremstyle{definition}
- \newtheorem{problem}[thm]{Problem}
+ \newtheorem{problem}[thm]{\protect\problemname}
EndPreamble
- Requires amsthm
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}\fi}
+ EndI18nPreamble
End
LatexName xca
LabelString "Exercise \thetheorem."
Preamble
+ \providecommand{\exercisename}{Exercise}
\theoremstyle{definition}
- \newtheorem{xca}[thm]{Exercise}
+ \newtheorem{xca}[thm]{\protect\exercisename}
EndPreamble
- Requires amsthm
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}\fi}
+ EndI18nPreamble
End
Shape Italic
EndFont
Preamble
+ \providecommand{\remarkname}{Remark}
\theoremstyle{remark}
- \newtheorem{rem}[thm]{Remark}
+ \newtheorem{rem}[thm]{\protect\remarkname}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}\fi}
+ EndI18nPreamble
End
LatexName claim
LabelString "Claim \thetheorem."
Preamble
+ \providecommand{\claimname}{Claim}
\theoremstyle{remark}
- \newtheorem{claim}[thm]{Claim}
+ \newtheorem{claim}[thm]{\protect\claimname}
EndPreamble
- Requires amsthm
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}\fi}
+ EndI18nPreamble
End
Shape Italic
EndFont
Preamble
+ \providecommand{\casename}{Case}
\newcounter{casectr}
\newenvironment{caseenv}
- {\begin{list}{{\itshape\ Case} \arabic{casectr}.}{%
+ {\begin{list}{{\itshape\ \protect\casename} \arabic{casectr}.}{%
\setlength{\leftmargin}{\labelwidth}
\addtolength{\leftmargin}{\parskip}
\setlength{\itemindent}{\listparindent}
\usecounter{casectr}}
{\end{list}}
EndPreamble
+ I18nPreamble
+ \AtBeginDocument{\ifx\LdfInit\undefined\relax\else\addto\captions$$lang{\renewcommand{\casename}{_(Case)}}\fi}
+ EndI18nPreamble
End
# Full author contact details are available in file CREDITS
-# This script will update a .layout file to format 6
+# This script will update a .layout file to current format
import os, re, string, sys
# Incremented to format 11, 14 October 2008 by rgh
# Add ProvidesModule, ExcludesModule tags
-currentFormat = 11
+# Incremented to format 12, 10 January 2009 by gb
+# Add I18NPreamble tag
+
+currentFormat = 12
def usage(prog_name):
re_AMSMaths = re.compile(r'^\s*Input amsmaths.inc\s*')
re_AMSMathsPlain = re.compile(r'^\s*Input amsmaths-plain.inc\s*')
re_AMSMathsSeq = re.compile(r'^\s*Input amsmaths-seq.inc\s*')
+ re_TocLevel = re.compile(r'^(\s*)(TocLevel)(\s+)(\S+)', re.IGNORECASE)
# counters for sectioning styles (hardcoded in 1.3)
counters = {"part" : "\\Roman{part}",
i = 0
only_comment = 1
counter = ""
+ toclevel = ""
label = ""
labelstring = ""
labelstringappendix = ""
i += 1
continue
+ # This just involved new features, not any changes to old ones
+ if format == 11:
+ i += 1
+ continue
+
if format == 10:
match = re_UseMod.match(lines[i])
if match:
latextype = string.lower(match.group(4))
latextype_line = i
+ # Remember the TocLevel line
+ match = re_TocLevel.match(lines[i])
+ if match:
+ toclevel = string.lower(match.group(4))
+
# Reset variables at the beginning of a style definition
match = re_Style.match(lines[i])
if match:
style = string.lower(match.group(4))
counter = ""
+ toclevel = ""
label = ""
space1 = ""
labelstring = ""
i += 1
# Add the TocLevel setting for sectioning styles
- if toclevels.has_key(style) and maxcounter <= toclevels[style]:
+ if toclevel == "" and toclevels.has_key(style) and maxcounter <= toclevels[style]:
lines.insert(i, '%sTocLevel %d' % (space1, toclevels[style]))
i += 1
#include "LaTeXFeatures.h"
+#include "Buffer.h"
#include "Color.h"
#include "BufferParams.h"
#include "Encoding.h"
tcpreamble << tclass.preamble();
+ typedef LanguageList::const_iterator lang_it;
+ lang_it const lbeg = UsedLanguages_.begin();
+ lang_it const lend = UsedLanguages_.end();
list<docstring>::const_iterator cit = usedLayouts_.begin();
list<docstring>::const_iterator end = usedLayouts_.end();
for (; cit != end; ++cit) {
tcpreamble << tclass[*cit].preamble();
+ tcpreamble << tclass[*cit].i18npreamble(buffer().language());
+ for (lang_it lit = lbeg; lit != lend; ++lit)
+ tcpreamble << tclass[*cit].i18npreamble(*lit);
}
return tcpreamble.str();
#include <config.h>
#include "Layout.h"
+#include "Language.h"
#include "TextClass.h"
#include "Lexer.h"
#include "Font.h"
+#include "support/Messages.h"
#include "support/debug.h"
+#include "support/lassert.h"
#include "support/lstrings.h"
+#include <boost/regex.hpp>
+
using namespace std;
using namespace lyx::support;
LT_FREE_SPACING,
LT_PASS_THRU,
//LT_HEADINGS,
+ LT_I18NPREAMBLE,
LT_ITEMSEP,
LT_KEEPEMPTY,
LT_LABEL_BOTTOMSEP,
{ "fill_top", LT_FILL_TOP },
{ "font", LT_FONT },
{ "freespacing", LT_FREE_SPACING },
+ { "i18npreamble", LT_I18NPREAMBLE },
{ "innertag", LT_INNERTAG },
{ "intitle", LT_INTITLE },
{ "itemsep", LT_ITEMSEP },
preamble_ = from_utf8(lex.getLongString("EndPreamble"));
break;
+ case LT_I18NPREAMBLE:
+ i18npreamble_ = from_utf8(lex.getLongString("EndI18NPreamble"));
+ break;
+
case LT_LABELTYPE:
readLabelType(lex);
break;
case LT_LABELSTRING: // label string definition
// FIXME: this means LT_ENDLABELSTRING may only
// occur after LT_LABELSTRING
- lex >> labelstring_;
+ lex >> labelstring_;
labelstring_ = trim(labelstring_);
labelstring_appendix_ = labelstring_;
break;
}
+docstring const Layout::i18npreamble(Language const * lang) const
+{
+ if (i18npreamble_.empty())
+ return i18npreamble_;
+ string preamble = subst(to_utf8(i18npreamble_), "$$lang",
+ lang->babel());
+#ifdef TEX2LYX
+ // tex2lyx does not have getMessages()
+ LASSERT(false, /**/);
+#else
+ // FIXME UNICODE
+ // boost::regex is not unicode-safe.
+ // Should use QRegExp or (boost::u32regex, but that requires ICU)
+ static boost::regex const reg("_\\(([^\\)]+)\\)");
+ boost::smatch sub;
+ while (boost::regex_search(preamble, sub, reg)) {
+ string const key = sub.str(1);
+ string translated;
+ if (isAscii(key))
+ translated = to_utf8(getMessages(lang->code()).get(key));
+ else {
+ lyxerr << "Warning: not translating `" << key
+ << "' because it is not pure ASCII." << endl;
+ translated = key;
+ }
+ preamble = subst(preamble, sub.str(), translated);
+ }
+#endif
+ return from_utf8(preamble);
+}
+
+
bool Layout::operator==(Layout const & rhs) const
{
// This is enough for the applications we actually make,
namespace lyx {
+class Language;
class Lexer;
class TextClass;
docstring const & category() const { return category_; }
///
docstring const & preamble() const { return preamble_; }
+ /// Get language dependent macro definitions needed for this layout
+ /// for language \p lang
+ docstring const i18npreamble(Language const * lang) const;
///
std::set<std::string> const & requires() const { return requires_; }
///
docstring category_;
/// Macro definitions needed for this layout
docstring preamble_;
+ /// Language dependent macro definitions needed for this layout
+ docstring i18npreamble_;
/// Packages needed for this layout
std::set<std::string> requires_;
};
docstring name_;
};
-int const FORMAT = 11;
+int const FORMAT = 12;
bool layout2layout(FileName const & filename, FileName const & tempfile)