]> git.lyx.org Git - features.git/commitdiff
Do not switch the input encoding inside documents using platex.
authorGünter Milde <milde@lyx.org>
Thu, 11 Apr 2019 16:19:44 +0000 (18:19 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:24 +0000 (15:48 +0200)
Fixes wrong and missing characters in text parts in other languages
(platex does not support "inputenc").

Fixes compilation errors due to desynchronized encoding switches.

autotests/export/latex/ja_wrong_auto_encoding.lyx
development/autotests/ignoredTests
development/autotests/invertedTests
lib/examples/ja/Multilingual_Typesetting_%28platex%29.lyx
src/BufferParams.cpp
src/LaTeXFeatures.cpp
src/insets/InsetListings.cpp
src/output_latex.cpp

index f75dc4f55e350c309c0c59967871c497ce5493c7..a3a4db9a16a5725f11194a58592a969b9bb4f6da 100644 (file)
@@ -1,47 +1,12 @@
 #LyX 2.4 created this file. For more info see https://www.lyx.org/
-\lyxformat 569
+\lyxformat 572
 \begin_document
 \begin_header
 \save_transient_properties true
 \origin unavailable
 \textclass scrbook
 \begin_preamble
-% DO NOT ALTER THIS PREAMBLE!!!
-%
-% This preamble is designed to ensure that the manual prints
-% out as advertised. If you mess with this preamble,
-% parts of the manual may not print out as expected.  If you
-% have problems LaTeXing this file, please contact 
-% the documentation team
-% email: lyx-docs@lists.lyx.org
 
-\IfFileExists{pxjahyper.sty}
-{\usepackage{pxjahyper}}
-
-% if pdflatex is used
-\usepackage{ifpdf}
-\ifpdf
-
- % set fonts for nicer pdf view
- \IfFileExists{lmodern.sty}
-  {\usepackage{lmodern}}{}
-
-\fi % end if pdflatex is used
-
-% the pages of the TOC are numbered roman
-% and a PDF-bookmark for the TOC is added
-\pagenumbering{roman}
-\let\myTOC\tableofcontents
-\renewcommand{\tableofcontents}{%
- \pdfbookmark[1]{\contentsname}{}
- \myTOC
- \cleardoublepage
- \pagenumbering{arabic}}
-
-% extra space for tables
-\newcommand{\extratablespace}[1]{\noalign{\vskip#1}}
-
-\usepackage{t1enc}
 \end_preamble
 \options bibliography=totoc,index=totoc,BCOR7.5mm,titlepage,captions=tableheading
 \use_default_options false
@@ -99,8 +64,8 @@ End
 \language_package default
 \inputencoding auto
 \fontencoding auto
-\font_roman "default" "default"
-\font_sans "default" "default"
+\font_roman "lmodern" "IPAexGothic"
+\font_sans "default" "IPAexMincho"
 \font_typewriter "default" "default"
 \font_math "auto" "auto"
 \font_default_family default
@@ -116,6 +81,8 @@ End
 \output_sync 0
 \bibtex_command default
 \index_command default
+\float_placement class
+\float_alignment class
 \paperfontsize 12
 \spacing single
 \use_hyperref true
index bef23a9eb19b180b1744b5e8106afec112652129..e1eda0e1ce8a698a795293ff2f8a11614c85d912 100644 (file)
@@ -61,6 +61,7 @@ export/examples/Modules/Chessboard_(lyx(16|20|21|22|23)|(pdf3|pdf5|dvi3)_texF)
 # 1. Exceptions to the following pattern (test cases with the right encoding):
 !export/.*(utf8|ascii)_pdf4_texF
 !export/examples/(|ar|ca|cs|da|de|el|es|eu|fa|fr|gl|he|hu|id|it|ja|ko|nb|nl|pl|pt|pt_BR|pt_PT|ro|ru|sk|sl|sr|sv|uk|zh_CN)/Welcome_pdf4_texF
+!export/examples/ja/Multilingual_Typesetting_.*CJK.*_pdf4_texF
 # 2. Catchall patterns to ignore the other tests:
 .*_pdf4_texF
 export/(doc|examples|templates)/(|ar|ca|cs|da|de|el|es|eu|fa|fr|gl|he|hu|id|it|ja|ko|nb|nl|pl|pt|pt_BR|pt_PT|ro|ru|sk|sl|sr|sv|uk|zh_CN)/.*pdf4_texF
@@ -82,7 +83,7 @@ export/examples/ja/Modules/Sweave.*
 #
 # Other Japanese documents use language "japanese" wich is tied to "platex"
 # (automatically invoked instead of "latex" to create a DVI file).
-# Export by other engines works with language "japanese-cjk", e.g.
+# Export by plain- and pdflatex engines works with language "japanese-cjk", e.g.
 !export/examples/ja/Multilingual_Typesetting_.*CJK.*
 # For a discussion of alternatives for Japanese with LaTeX , see also
 # http://www.preining.info/blog/2014/12/writing-japanese-in-latex-part-1-introduction/
index 0fbaa13276af396f5b66bc042eb133cc04e6ec73..40e2afc0b66927354bd1357f08ca4e0974a23065 100644 (file)
@@ -188,8 +188,6 @@ export/doc/ar/UserGuide_lyx(22|23)
 
 #11532 inputencoding desynchronisation
 export/export/latex/misplaced-inputenc-switch_pdf2
-# Error in Japanese document if LyX-logo is preceded by foreign language text
-export/export/latex/ja_wrong_auto_encoding_(dvi|pdf(|3)).*
 
 
 # ==============================================================
index 212228bde084e4d8df500de2198483e3e4d7cebc..cb4af5aabfe9b5a16669cbb17d91d5c94fb53c98 100644 (file)
@@ -125,7 +125,15 @@ Russisch: Привет с
 
 \begin_layout Standard
 Text in some other languages with correct language setting (not all languages
- supported by LyX are compatible with pLaTeX):
+ supported by LyX are compatible with pLaTeX, try 
+\begin_inset Quotes eld
+\end_inset
+
+japanese (CJK)
+\begin_inset Quotes erd
+\end_inset
+
+):
 \end_layout
 
 \begin_layout Standard
@@ -143,27 +151,6 @@ Afrikaans: Good dag minher.
 
 \begin_layout Standard
 
-\emph on
-Missing and wrong characters with 
-\emph default
-Language\SpecialChar menuseparator
-Encoding 
-\begin_inset Quotes eld
-\end_inset
-
-language default
-\emph on
-
-\begin_inset Quotes erd
-\end_inset
-
-
-\emph default
-:
-\end_layout
-
-\begin_layout Standard
-
 \lang swedish
 Swedish: Hej då.
 \end_layout
index aee184cb006c0c15086ac8112a8088b53e00d7d9..c0f8a60be932950faaf6f1c6f08315c5f4c34753 100644 (file)
@@ -3259,9 +3259,9 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                        // list all input encodings used in the document
                        encoding_set = features.getEncodingSet(doc_encoding);
 
-               // If the "japanese" package (i.e. pLaTeX) is used,
-               // inputenc must be omitted.
-               // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
+               // The "japanese" babel-language requires  the pLaTeX engine
+               // which conflicts with "inputenc".
+               // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
                if ((!encoding_set.empty() || package == Encoding::inputenc)
                    && !features.isRequired("japanese")
                    && !features.isProvided("inputenc")) {
index bed11deff0af715b5fea336fb56bc2feb11bd37a..301d3c175c744cd32fab830af1b5346555bd8fa6 100644 (file)
@@ -747,7 +747,7 @@ void LaTeXFeatures::useLanguage(Language const * lang)
        // They use the CJK package
        if (lang->encoding()->package() == Encoding::CJK)
                require("CJK");
-       // japanese package is special
+       // japanese babel language is special (tied to the pLaTeX engine).
        if (lang->encoding()->package() == Encoding::japanese)
                require("japanese");
 }
@@ -879,8 +879,7 @@ set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
        set<string> encs;
        for (auto const & lang : UsedLanguages_)
                if (lang->encoding()->latexName() != doc_encoding &&
-                   (lang->encoding()->package() == Encoding::inputenc
-                    || lang->encoding()->package() == Encoding::japanese))
+                   lang->encoding()->package() == Encoding::inputenc)
                        encs.insert(lang->encoding()->latexName());
        return encs;
 }
index b50e92623e4489181489cbf73f23737aa85be4f5..8ff6108c1c4b26d1637066e679cfd6a65c0498e5 100644 (file)
@@ -127,8 +127,7 @@ Encoding const * InsetListings::forcedEncoding(Encoding const * inner_enc,
        // Minted can deal with all encodings.
        if (buffer().params().use_minted
                || inner_enc->name() == "utf8-plain"
-               || (buffer().params().encoding().package() == Encoding::japanese
-                       && inner_enc->package() == Encoding::japanese)
+               || buffer().params().encoding().package() == Encoding::japanese
                || inner_enc->hasFixedWidth())
                return 0;
 
index dacfa7f1004df10e963fcad08d0c6d4b6bc5eb54..80af66451d85050f147535ae817b459d9bd8981a 100644 (file)
@@ -984,6 +984,7 @@ void TeXOnePar(Buffer const & buf,
        // \inputencoding command; the encoding switch will occur when necessary
        if (bparams.inputenc == "auto"
                && !runparams.isFullUnicode() // Xe/LuaTeX use one document-wide encoding  (see also switchEncoding())
+               && runparams.encoding->package() != Encoding::japanese
                && runparams.encoding->package() != Encoding::none) {
                // Look ahead for future encoding changes.
                // We try to output them at the beginning of the paragraph,
@@ -1627,39 +1628,41 @@ void latexParagraphs(Buffer const & buf,
        }
 }
 
-
+// Switch the input encoding for some part(s) of the document.
 pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                   OutputParams const & runparams, Encoding const & newEnc,
                   bool force, bool noswitchmacro)
 {
-       // Never switch encoding with non-TeX fonts (always "utf8plain") or
-       // with LuaTeX and TeX fonts (only one encoding accepted by luainputenc).
+       // Never switch encoding with non-TeX fonts (always "utf8plain"),
+       // with LuaTeX and TeX fonts (only one encoding accepted by luainputenc),
+       // or if we're in a moving argument or inherit the outer encoding.
        if (bparams.useNonTeXFonts
                || runparams.flavor == OutputParams::LUATEX
                || runparams.flavor == OutputParams::DVILUATEX
                || newEnc.name() == "inherit")
          return make_pair(false, 0);
 
-       Encoding const & oldEnc = *runparams.encoding;
-       bool moving_arg = runparams.moving_arg;
-       if (!force
-           && ((bparams.inputenc != "auto" && bparams.inputenc != "default") || moving_arg))
+       // Only switch for auto-selected legacy encodings (inputenc setting
+       // "auto" or "default").
+       // The "listings" environment can force a switch also with other
+       // encoding settings (it does not support variable width encodings
+       // (utf8, jis, ...) under 8-bit latex engines).
+       if (!force && ((bparams.inputenc != "auto" && bparams.inputenc != "default")
+                                  || runparams.moving_arg))
                return make_pair(false, 0);
 
-       // Do nothing if the encoding is unchanged.
-       if (oldEnc.name() == newEnc.name())
+       Encoding const & oldEnc = *runparams.encoding;
+       // Do not switch, if the encoding is unchanged or switching is not supported.
+       if (oldEnc.name() == newEnc.name()
+               || oldEnc.package() == Encoding::japanese
+               || oldEnc.package() == Encoding::none
+               || newEnc.package() == Encoding::none)
                return make_pair(false, 0);
-
        // FIXME We ignore encoding switches from/to encodings that do
        // neither support the inputenc package nor the CJK package here.
-       // This does of course only work in special cases (e.g. switch from
-       // tis620-0 to latin1, but the text in latin1 contains ASCII only),
-       // but it is the best we can do
-       //
-       // 2019-01-08 Possibly no longer required since tis620-0 is supported
-       // by inputenc (but check special encodings "utf8-plain" and "default").
-       if (oldEnc.package() == Encoding::none || newEnc.package() == Encoding::none)
-               return make_pair(false, 0);
+       // This may fail for characters not supported by "unicodesymbols"
+       // or for non-ASCII characters in "listings"
+       // but it is the best we can do.
 
        // change encoding
        LYXERR(Debug::LATEX, "Changing LaTeX encoding from "
@@ -1673,7 +1676,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
        switch (newEnc.package()) {
                case Encoding::none:
                case Encoding::japanese:
-                       // shouldn't ever reach here, see above
+                       // shouldn't ever reach here (see above) but avoids warning.
                        return make_pair(true, 0);
                case Encoding::inputenc: {
                        int count = inputenc_arg.length();
@@ -1698,8 +1701,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                                count += 7;
                                state->open_encoding_ = inputenc;
                        }
-                       // with the japanese option, inputenc is omitted.
-                       if (runparams.use_japanese || noswitchmacro)
+                       if (noswitchmacro)
                                return make_pair(true, count);
                        os << "\\inputencoding{" << inputenc_arg << '}';
                        return make_pair(true, count + 16);