commit ccf93fc0d66a338ce4c51617895c90cf99d66295
Author: Juergen Spitzmueller <[email protected]>
Date:   Fri Apr 19 17:18:18 2019 +0200

    Use proper listings font styles with polyglossia and RTL
    
    Fixes: #11554
    
    Also load color with minted and polyglossia/RTL, as minted loads it
    too late.
    
    (cherry picked from commit 3e516a6219f8a768ef0413876109160dd5935cc1)
---
 src/LaTeXFeatures.h          |    4 ++--
 src/insets/InsetListings.cpp |   24 ++++++++++++++++++++++--
 status.23x                   |    2 ++
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index 137f5d7..85f3771 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -177,13 +177,13 @@ public:
        void setHTMLTitle(docstring const & t) { htmltitle_ = t; }
        ///
        docstring const & htmlTitle() const { return htmltitle_; }
+       ///
+       bool hasRTLLanguage() const;
 
 private:
        ///
        void useLayout(docstring const &, int);
        ///
-       bool hasRTLLanguage() const;
-       ///
        std::list<docstring> usedLayouts_;
        ///
        std::list<docstring> usedInsetLayouts_;
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
index d114e7e..88ab71a 100644
--- a/src/insets/InsetListings.cpp
+++ b/src/insets/InsetListings.cpp
@@ -147,6 +147,22 @@ void InsetListings::latex(otexstream & os, OutputParams 
const & runparams) const
        // of the listings package (see page 25 of the manual)
        bool const isInline = params().isInline();
        bool const use_minted = buffer().params().use_minted;
+       static regex const 
reg1("(.*)(basicstyle=\\{)([^\\}]*)(\\\\ttfamily)([^\\}]*)(\\})(.*)");
+       static regex const 
reg2("(.*)(basicstyle=\\{)([^\\}]*)(\\\\rmfamily)([^\\}]*)(\\})(.*)");
+       static regex const 
reg3("(.*)(basicstyle=\\{)([^\\}]*)(\\\\sffamily)([^\\}]*)(\\})(.*)");
+       if (runparams.use_polyglossia && runparams.local_font->isRightToLeft()) 
{
+               // We need to use the *latin switches (#11554)
+               smatch sub;
+               if (regex_match(param_string, sub, reg1))
+                       param_string = sub.str(1) + sub.str(2) + sub.str(3) + 
sub.str(4)
+                                       + "latin"  + sub.str(5) + sub.str(6) + 
sub.str(7);
+               if (regex_match(param_string, sub, reg2))
+                       param_string = sub.str(1) + sub.str(2) + sub.str(3) + 
sub.str(4)
+                                       + "latin"  + sub.str(5) + sub.str(6) + 
sub.str(7);
+               if (regex_match(param_string, sub, reg3))
+                       param_string = sub.str(1) + sub.str(2) + sub.str(3) + 
sub.str(4)
+                                       + "latin"  + sub.str(5) + sub.str(6) + 
sub.str(7);
+       }
        string minted_language;
        string float_placement;
        bool const isfloat = params().isFloat();
@@ -159,11 +175,11 @@ void InsetListings::latex(otexstream & os, OutputParams 
const & runparams) const
                        if (prefixIs(opts[i], "float")) {
                                if (prefixIs(opts[i], "float="))
                                        float_placement = opts[i].substr(6);
-                               opts.erase(opts.begin() + i--);
+                               opts.erase(opts.begin() + int(i--));
                        }
                        else if (prefixIs(opts[i], "language=")) {
                                minted_language = opts[i].substr(9);
-                               opts.erase(opts.begin() + i--);
+                               opts.erase(opts.begin() + int(i--));
                        }
                }
                param_string = getStringFromVector(opts, ",");
@@ -489,6 +505,10 @@ void InsetListings::validate(LaTeXFeatures & features) 
const
                OutputParams rp = features.runparams();
                if (!params().isFloat() && !getCaption(rp).str.empty())
                        features.require("lyxmintcaption");
+               if (features.usePolyglossia() && features.hasRTLLanguage())
+                       // minted loads color, but color must be loaded before 
bidi
+                       // (i.e., polyglossia)
+                       features.require("color");
        } else {
                features.require("listings");
                if (contains(param_string, "\\color"))
diff --git a/status.23x b/status.23x
index 58da016..7051aa5 100644
--- a/status.23x
+++ b/status.23x
@@ -100,6 +100,8 @@ What's new
 - Fix text direction of namerefs in RTL scripts when using polyglossia (bidi)
   (bug 11518).
 
+- Use proper listings font styles with polyglossia (bidi) and RTL (bug 11554).
+
 - Fix LaTeX export of query strings in Hyperlinks (bugs 11482, 11511).
 
 - Fix breakage caused by commas in the caption of listings (bug 11484).

Reply via email to