]> git.lyx.org Git - lyx.git/commitdiff
Prune white space after the separating comma of options
authorEnrico Forestieri <forenr@lyx.org>
Sat, 17 Jun 2017 18:41:29 +0000 (20:41 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sat, 17 Jun 2017 18:41:29 +0000 (20:41 +0200)
Both listings and minted allow for many complex options. So, a latex
source can be easily written as

\documentclass{article}
\usepackage{minted}
\usepackage{graphicx}
\usepackage{dingbat}
\begin{document}
\begin{minted}[breaklines=true,
               breakautoindent=false,
               breaksymbolleft=\raisebox{0.8ex}{
                   \small\reflectbox{\carriagereturn}},
               breaksymbolindentleft=0pt,
               breaksymbolsepleft=0pt,
               breaksymbolright=\small\carriagereturn,
               breaksymbolindentright=0pt,
               breaksymbolsepright=0pt]{Python}
def f(x):
    return 'Some text' + str(x) + 'some more text' + str(x) + 'even more text that goes on for a while'
\end{minted}
\end{document}

The used text editor can therefore add a mixture of tabs and spaces.
The white space after the options is not a problem and the imported
file compiles just fine, but the validator gets confused and doesn't
validate them. This would entail a difficult editing of the options
only to have them validated. So, better remove the white space.

src/tex2lyx/text.cpp

index e5180cffe690f8920bc82ec0f346acb18b0573a6..2e7f08a596d6560ac738d78c3da072e36c1a4877 100644 (file)
@@ -1327,6 +1327,11 @@ void parse_listings(Parser & p, ostream & os, Context & parent_context,
        parent_context.check_layout(os);
        begin_inset(os, "listings\n");
        string arg = p.hasOpt() ? subst(p.verbatimOption(), "\n", "") : string();
+       size_t i;
+       while ((i = arg.find(", ")) != string::npos
+                       || (i = arg.find(",\t")) != string::npos)
+               arg.erase(i + 1, 1);
+
        if (use_minted) {
                string const language = p.getArg('{', '}');
                p.skip_spaces(true);