Account for babel's bidi option (#12866)

bidi=bidi-{r,l} load the bidi package
This commit is contained in:
Juergen Spitzmueller 2023-08-17 14:25:33 +02:00
parent a6b83b7444
commit 315c2f132a
9 changed files with 41 additions and 17 deletions

View 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")

View 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;

View 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

View File

@ -51,10 +51,4 @@ bool OutputParams::isFullUnicode() const
|| flavor == Flavor::XeTeX;
}
bool OutputParams::useBidiPackage() const
{
return use_polyglossia && flavor == Flavor::XeTeX;
}
} // namespace lyx

View 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;

View 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:

View 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);

View 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);
}

View 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) {