commit 7a87599a3e050974f915a320c815aa13c5120d22
Author: Günter Milde <mi...@lyx.org>
Date:   Sat Apr 27 16:00:29 2019 +0200

    Load inputenc after babel with Thai.
    
    "thai.ldf" breaks "inputenc" by changing catcodes.
    Loading "inputenc" after "babel" allows a workaround.
---
 autotests/export/latex/en-th_language-default.lyx |    6 ++--
 autotests/export/latex/en-th_utf8.lyx             |   23 ++++++++++++--------
 development/autotests/ignoredTests                |    2 +-
 development/autotests/invertedTests               |   10 +--------
 development/autotests/unreliableTests             |   15 -------------
 lib/languages                                     |   22 ++++++++++----------
 src/BufferParams.cpp                              |   12 ++++++++--
 7 files changed, 39 insertions(+), 51 deletions(-)

diff --git a/autotests/export/latex/en-th_language-default.lyx 
b/autotests/export/latex/en-th_language-default.lyx
index 5103578..a10f028 100644
--- a/autotests/export/latex/en-th_language-default.lyx
+++ b/autotests/export/latex/en-th_language-default.lyx
@@ -6,7 +6,7 @@
 \origin unavailable
 \textclass article
 \begin_preamble
-\AtBeginDocument{\usepackage{fonts-tlwg}}
+
 \end_preamble
 \use_default_options true
 \maintain_unincluded_children false
@@ -27,7 +27,7 @@
 \use_microtype false
 \use_dash_ligatures true
 \graphics default
-\default_output_format default
+\default_output_format pdf2
 \output_sync 0
 \bibtex_command default
 \index_command default
@@ -84,7 +84,7 @@
 \begin_body
 
 \begin_layout Subsection*
-Thai
+Test workaround for Thai language
 \end_layout
 
 \begin_layout Standard
diff --git a/autotests/export/latex/en-th_utf8.lyx 
b/autotests/export/latex/en-th_utf8.lyx
index 12958db..ce9f924 100644
--- a/autotests/export/latex/en-th_utf8.lyx
+++ b/autotests/export/latex/en-th_utf8.lyx
@@ -5,18 +5,15 @@
 \save_transient_properties true
 \origin unavailable
 \textclass article
-\begin_preamble
-\AtBeginDocument{\usepackage{fonts-tlwg}}
-\end_preamble
 \use_default_options true
 \maintain_unincluded_children false
 \language english
 \language_package default
 \inputencoding utf8
 \fontencoding auto
-\font_roman "lmodern" "FreeSerif"
-\font_sans "default" "FreeSans"
-\font_typewriter "default" "FreeMono"
+\font_roman "lmodern" "Norasi"
+\font_sans "default" "Garuda"
+\font_typewriter "default" "Tlwg Mono"
 \font_math "auto" "auto"
 \font_default_family default
 \use_non_tex_fonts false
@@ -84,7 +81,7 @@
 \begin_body
 
 \begin_layout Subsection*
-Thai
+Test workaround for Thai language
 \end_layout
 
 \begin_layout Standard
@@ -203,7 +200,11 @@ uc/lccode changes prevent up/downcasing of high-bit 
characters
 \begin_inset Newline newline
 \end_inset
 
-(lösen → 
+(lösen 
+\begin_inset Formula $→$
+\end_inset
+
+ 
 \begin_inset ERT
 status open
 
@@ -227,7 +228,11 @@ status open
 
 \end_inset
 
-, LÖSEN → 
+, LÖSEN 
+\begin_inset Formula $→$
+\end_inset
+
+ 
 \begin_inset ERT
 status open
 
diff --git a/development/autotests/ignoredTests 
b/development/autotests/ignoredTests
index dccf88b..b14e9a2 100644
--- a/development/autotests/ignoredTests
+++ b/development/autotests/ignoredTests
@@ -171,4 +171,4 @@ lyx2lyx/export/latex/.*
 export/export/latex/.*(lyx..|xhtml)
 
 # don't test with non-TeX fonts:
-export/export/latex/en-th_(LTH|language-default).*systemF
+#export/export/latex/en-th_(LTH|language-default).*systemF
diff --git a/development/autotests/invertedTests 
b/development/autotests/invertedTests
index fe176dd..4e7a0a5 100644
--- a/development/autotests/invertedTests
+++ b/development/autotests/invertedTests
@@ -74,7 +74,7 @@ 
export/templates/Articles/International_Union_of_Crystallography.*_pdf4_systemF
 export/templates/Articles/R_Journal_(dvi3|pdf[45])_systemF
 #export/templates/Articles/Kluwer_.*_systemF
 
-# Babel and fontenc not fails for some supported languages
+# Babel and fontenc fails for some supported languages
 # * check BabelPremble definitions in lib/languages
 # * fails also due to #11522, see "lyxbugs" below.
 export/export/latex/supported-languages_.*_systemF
@@ -332,14 +332,6 @@ export/.*/he/.*_texF
 # See comment in unreliableTests
 export/export/latex/uk-babel-date-missing-chars-with-ascii_pdf5_texF
 
-# Thai
-# babel-thai globally changes catcodes for high-bit chars
-# which prevents parsing of utf8 with vanilla inputenc (utf8x works)
-# see also unreliable.wrong_output and unreliable.varying_versions
-export/export/latex/en-th_utf8_(dvi|pdf[23]?|pdf4_texF)
-# luainputenc fails with TL19:
-export/export/latex/en-th_language-default_(dvi3|pdf5)_texF
-
 
 # ================================================
 Sublabel: externalissues
diff --git a/development/autotests/unreliableTests 
b/development/autotests/unreliableTests
index 1787602..e939e2c 100644
--- a/development/autotests/unreliableTests
+++ b/development/autotests/unreliableTests
@@ -143,12 +143,6 @@ export/templates/Articles/American_Astronomical_Society_.*
 export/templates/Articles/Association_for_Computing_Machinery_pdf[45]_texF
 
 
-# Thai
-# Babel-thai globally changes catcodes for high-bit chars
-# which clashes with vanilla inputenc (utf8x and 8-bit input encodings and
-# luainputenc work with TL17 but luainputenc fails with TL19):
-export/export/latex/en-th_language-default_(dvi3|pdf5)_texF
-
 Sublabel: wrong_output
 ######################
 # Export does not fail but the resulting document has errors.
@@ -173,15 +167,6 @@ export/export/latex/es_auto-legacy_texF
 export/export/latex/uk-babel-date-missing-chars-with-ascii_.*_texF
 export/doc/uk/Intro_.*_texF
 
-# Thai
-# Babel-thai globally changes catcodes for high-bit chars
-# which prevents parsing of utf8 with vanilla inputenc (utf8x works).
-# see also invertedTests
-export/export/latex/en-th_language-default_(dvi|pdf).?
-export/export/latex/en-th_utf8_(dvi|pdf).*
-#
-# only ASCII characters in DVI (LuaTeX) with non-TeX fonts:
-export/export/latex/en-th_utf8_dvi3_systemF
 
 # LyX issues
 # **********
diff --git a/lib/languages b/lib/languages
index 3358366..9e6731f 100644
--- a/lib/languages
+++ b/lib/languages
@@ -1366,25 +1366,25 @@ Language thai
        FontEncoding     LTH
        DateFormats      "dd MMMM yyyy|d MMM yyyy|dd/MM/yyyy"
        LangCode         th_TH
+       # The first workaround requires loading inputenc after babel
+       # (cf. BufferParams.cpp):
        PostBabelPreamble
-         % Restore \coyright definition corrupted by lthenc.def
-         \DeclareRobustCommand{\copyright}{%
-           \ifmmode{\nfss@text{\textcopyright}}\else\textcopyright\fi}
-         \DeclareTextSymbol{\textcopyright}{LTH}{8}
          % Restore catcodes changed by thai.ldf (active characters required 
for inputenc)
          \@tempcnta=161%
          \@whilenum\@tempcnta<252\do{%
            \catcode\@tempcnta=13
            \advance\@tempcnta\@ne
          }%      
+         % Restore \coyright definition corrupted by lthenc.def
+         \DeclareRobustCommand{\copyright}{%
+           \ifmmode{\nfss@text{\textcopyright}}\else\textcopyright\fi}
+         \DeclareTextSymbol{\textcopyright}{LTH}{8}
+          % set up Thai fonts as substitue for the default families
+          \usepackage{substitutefont}
+          \substitutefont{LTH}{\rmdefault}{norasi}
+          \substitutefont{LTH}{\sfdefault}{garuda}
+          \substitutefont{LTH}{\ttdefault}{ttypist}
        EndPostBabelPreamble
-       # Fixme: load font package?
-       # +1 support for font attributes in thai emphasizing etc.
-       # -1 forces ComputerModern as "non-thai" font
-       # TODO: set norasi as surrogate font for LTH (substitutefont.sty)
-       # PostBabelPreamble
-       #   \usepackage{fonts-tlwg}
-       # EndPostBabelPreamble
 End
 
 # not supported by babel
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 8478f8c..8b2afe1 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -1801,10 +1801,11 @@ bool BufferParams::writeLaTeX(otexstream & os, 
LaTeXFeatures & features,
        if (features.mustProvide("pmboxdraw"))
                os << "\\usepackage{pmboxdraw}\n";
        
-       // FIXME: In any document containing text in Thai language, 
-       // we must load babel before inputenc (see lib/languages).
        // handle inputenc etc.
-       writeEncodingPreamble(os, features);
+       // (In documents containing text in Thai language, 
+       // we must load inputenc after babel, see lib/languages).
+       if (!contains(features.getBabelPostsettings(), from_ascii("thai.ldf")))
+         writeEncodingPreamble(os, features);
 
        // includeonly
        if (!features.runparams().includeall && !included_children_.empty()) {
@@ -2288,6 +2289,11 @@ bool BufferParams::writeLaTeX(otexstream & os, 
LaTeXFeatures & features,
                                          !lyxrc.language_global_options)) + 
'\n';
                os << features.getBabelPostsettings();
        }
+       // In documents containing text in Thai language, 
+       // we must load inputenc after babel (see lib/languages).
+       if (contains(features.getBabelPostsettings(), from_ascii("thai.ldf")))
+         writeEncodingPreamble(os, features);
+
        if (features.isRequired("bicaption"))
                os << "\\usepackage{bicaption}\n";
        if (!listings_params.empty()

Reply via email to