]> git.lyx.org Git - features.git/commitdiff
Account for babel's bidi option (#12866)
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 17 Aug 2023 12:25:33 +0000 (14:25 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 17 Aug 2023 12:25:33 +0000 (14:25 +0200)
bidi=bidi-{r,l} load the bidi package

src/BufferParams.cpp
src/BufferParams.h
src/Font.cpp
src/OutputParams.cpp
src/OutputParams.h
src/Paragraph.cpp
src/insets/InsetCitation.cpp
src/insets/InsetRef.cpp
src/insets/InsetTabular.cpp

index 875b8d0ca856c9107827ce81676c6215169bcf91..3dad8c69133f06f937f4a567d665b7ec35c3bf14 100644 (file)
@@ -2948,6 +2948,33 @@ bool BufferParams::isLiterate() const
 }
 
 
+bool BufferParams::hasPackageOption(string const package, string const opt) const
+{
+       for (auto const & p : documentClass().packageOptions())
+               if (package == p.first && opt == p.second)
+                       return true;
+       return false;
+}
+
+
+bool BufferParams::useBidiPackage(OutputParams const & rp) const
+{
+       return (rp.use_polyglossia
+               // as of babel 3.29, bidi=bidi-* is supported by babel
+               // So we check whether we use a respective version and
+               // whethert bidi-r or bidi-l have been requested either via class
+               // or package options
+               || (rp.use_babel
+                   && LaTeXFeatures::isAvailableAtLeastFrom("babel", 2019, 4, 3)
+                   && (hasPackageOption("babel", "bidi-r")
+                       || hasPackageOption("babel", "bidi-l")
+                       || contains(options, "bidi-r")
+                       || contains(options, "bidi-l")))
+               )
+               && rp.flavor == Flavor::XeTeX;
+}
+
+
 void BufferParams::readPreamble(Lexer & lex)
 {
        if (lex.getString() != "\\begin_preamble")
index 77b4856b4d3bca7b6a435c85c467f1a510354d67..2a2e0f3087122a2fcb7d156f7e0ad4f1c61d48b0 100644 (file)
@@ -49,6 +49,7 @@ class LayoutFile;
 class LayoutFileIndex;
 class Length;
 class Lexer;
+class OutputParams;
 class otexstream;
 class PDFOptions;
 class Spacing;
@@ -194,6 +195,10 @@ public:
        bool isLatex() const;
        /// returns \c true if the buffer contains a Wed document
        bool isLiterate() const;
+       /// Is this package option requested?
+       bool hasPackageOption(std::string const package, std::string const opt) const;
+       /// Do we use the bidi package (which does some reordering and stuff)?
+       bool useBidiPackage(OutputParams const & rp) const;
 
        /// return the format of the buffer on a string
        std::string bufferFormat() const;
index aa8c235f11a407590d5cb59400dfcd64a173f3c2..8c73e91f37345e545136d6651b5646897be11e9a 100644 (file)
@@ -426,7 +426,7 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
        // the numbers are written Left-to-Right. ArabTeX package
        // and bidi (polyglossia with XeTeX) reorder the number automatically
        // but the packages used for Hebrew and Farsi (Arabi) do not.
-       if (!runparams.useBidiPackage()
+       if (!bparams.useBidiPackage(runparams)
            && !runparams.pass_thru
            && bits_.number() == FONT_ON
            && prev.fontInfo().number() != FONT_ON
@@ -604,7 +604,7 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
        // the numbers are written Left-to-Right. ArabTeX package
        // and bidi (polyglossia with XeTeX) reorder the number automatically
        // but the packages used for Hebrew and Farsi (Arabi) do not.
-       if (!runparams.useBidiPackage()
+       if (!bparams.useBidiPackage(runparams)
            && !runparams.pass_thru
            && bits_.number() == FONT_ON
            && next.fontInfo().number() != FONT_ON
index dd98c52bbc7a8f4f708b843a5688d81a373d0109..7c22cb1348eec320b28caa36587bfbd25436bf73 100644 (file)
@@ -51,10 +51,4 @@ bool OutputParams::isFullUnicode() const
                        || flavor == Flavor::XeTeX;
 }
 
-
-bool OutputParams::useBidiPackage() const
-{
-       return use_polyglossia && flavor == Flavor::XeTeX;
-}
-
 } // namespace lyx
index 40a7a47785e01faac4a13535563c1868fdd43969..9d9a7ae8f83248bb449bb18fd1b7c421cb10fce6 100644 (file)
@@ -83,8 +83,6 @@ public:
        bool isLaTeX() const;
        /// does this flavour support full unicode?
        bool isFullUnicode() const;
-       /// Do we use the bidi package (which does some reordering and stuff)?
-       bool useBidiPackage() const;
 
        /// Same, but for math output, which only matter is XHTML output.
        MathFlavor math_flavor = NotApplicable;
index d4658faf845d7e49fb498fe4432d1c8ed7da37f5..30a5e5eb350778e886d2ef328c46ee3459a6ff77 100644 (file)
@@ -2055,7 +2055,7 @@ char_type Paragraph::getUChar(BufferParams const & bparams,
        // or if we use poylglossia/bidi (XeTeX)
        // or with babel and Xe/LuaTeX.
        if (!getFontSettings(bparams, pos).isRightToLeft()
-           || rp.useBidiPackage()
+           || bparams.useBidiPackage(rp)
            || (rp.use_babel && rp.isFullUnicode()))
                return c;
 
@@ -2548,7 +2548,7 @@ int Paragraph::Private::startTeXParParams(BufferParams const & bparams,
        // RTL in classic (PDF)LaTeX (without the Bidi package)
        // Luabibdi (used by LuaTeX) behaves like classic
        bool const rtl_classic = owner_->getParLanguage(bparams)->rightToLeft()
-               && !runparams.useBidiPackage();
+               && !bparams.useBidiPackage(runparams);
 
        switch (curAlign) {
        case LYX_ALIGN_NONE:
@@ -2612,7 +2612,7 @@ bool Paragraph::Private::endTeXParParams(BufferParams const & bparams,
        // RTL in classic (PDF)LaTeX (without the Bidi package)
        // Luabibdi (used by LuaTeX) behaves like classic
        bool const rtl_classic = owner_->getParLanguage(bparams)->rightToLeft()
-               && !runparams.useBidiPackage();
+               && !bparams.useBidiPackage(runparams);
 
        switch (curAlign) {
        case LYX_ALIGN_NONE:
index c684b4c7a97748a25ea74705bc7546c8072e5e56..b1d01f4d67b5fb2856a5213f4f384c425c5c3bcb 100644 (file)
@@ -543,7 +543,7 @@ bool InsetCitation::forceLTR(OutputParams const & rp) const
        // We have to force LTR for numeric references
        // [= bibliography, plain BibTeX, numeric natbib
        // and biblatex]. Except for XeTeX/bidi. See #3005.
-       if (rp.useBidiPackage())
+       if (buffer().masterParams().useBidiPackage(rp))
                return false;
        return (buffer().masterParams().citeEngine() == "basic"
                || buffer().masterParams().citeEngineType() == ENGINE_TYPE_NUMERICAL);
index 49cf630b78b6ed0b97d4ef8c5522586cc9a69da9..0938b47e2713db4f636dae909e36fe7248431cf7 100644 (file)
@@ -611,7 +611,7 @@ bool InsetRef::forceLTR(OutputParams const & rp) const
        // * Parentheses are automatically swapped with XeTeX/bidi 
        //   [not with LuaTeX/luabidi] (see #11626).
        // FIXME: Re-Audit all other RTL cases.
-       if (rp.useBidiPackage())
+       if (buffer().masterParams().useBidiPackage(rp))
                return false;
        return (getCmdName() != "nameref" || !buffer().masterParams().useNonTeXFonts);
 }
index 69f9e73e59f0f0f11e125f2c80e4ba5449048455..e8fc1baf97398638e33181593954e0c941c68c1a 100644 (file)
@@ -3180,7 +3180,7 @@ void Tabular::TeXRow(otexstream & os, row_type row,
        // Luabibdi (used by LuaTeX) behaves like classic
        bool const bidi_rtl =
                runparams.local_font->isRightToLeft()
-               && runparams.useBidiPackage();
+               && buffer().params().useBidiPackage(runparams);
        bool const ct = !buffer().params().output_changes;
        idx_type lastcell =
                bidi_rtl ? getFirstCellInRow(row, ct) : getLastCellInRow(row, ct);
@@ -3352,7 +3352,7 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const
        // order for RTL (#9686). Thus we use this list.
        bool const bidi_rtl =
                runparams.local_font->isRightToLeft()
-               && runparams.useBidiPackage();
+               && buffer().params().useBidiPackage(runparams);
        list<col_type> columns;
        list<col_type> logical_columns;
        for (col_type cl = 0; cl < ncols(); ++cl) {