In order to implement a linguistic feature properly (support for the forest
package to generate structure trees), I need a way to pass only selected
chars verbatim (here, [ and ], since these are active characters in the
package and thus must not be escaped by braces). Making the whole inset
PassThru is not a good option, neither the need to use ERT for the brackets.

Thus, I propose the following patch, which adds PassThruChars tags to
InsetLayout and Layout, where a comma.separated list of characters that
should be treated verbatim can be specified.

I think this might also be useful in other cases.

Comments?
Jürgen
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index 1957633..95412ca 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -180,6 +180,9 @@ import os, re, string, sys
 # Incremented to format 54, 11 Jan 2014 by gb
 # New InsetLayout tag "FixedWidthPreambleEncoding"
 
+# Incremented to format 55, 20 April 2015 by spitz
+# New InsetLayout and Layout tags "PassThruChars"
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -187,7 +190,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.py script to update all
 # layout files to the new format.
 
-currentFormat = 54
+currentFormat = 55
 
 
 def usage(prog_name):
@@ -411,7 +414,7 @@ def convert(lines):
                 i += 1
             continue
 
-        if format >= 50 and format <= 53:
+        if format >= 50 and format <= 54:
             # nothing to do.
             i += 1
             continue
diff --git a/src/Layout.cpp b/src/Layout.cpp
index bb31287..be51756 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -51,6 +51,7 @@ enum LayoutTags {
        LT_FONT,
        LT_FREE_SPACING,
        LT_PASS_THRU,
+       LT_PASS_THRU_CHARS,
        LT_PARBREAK_IS_NEWLINE,
        LT_ITEMCOMMAND,
        LT_ITEMSEP,
@@ -235,6 +236,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass 
const & tclass)
                { "parsep",         LT_PARSEP },
                { "parskip",        LT_PARSKIP },
                { "passthru",       LT_PASS_THRU },
+               { "passthruchars",  LT_PASS_THRU_CHARS },
                { "preamble",       LT_PREAMBLE },
                { "refprefix",      LT_REFPREFIX },
                { "requires",       LT_REQUIRES },
@@ -548,6 +550,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass 
const & tclass)
                        lex >> pass_thru;
                        break;
 
+               case LT_PASS_THRU_CHARS:
+                       lex >> pass_thru_chars;
+                       break;
+
                case LT_PARBREAK_IS_NEWLINE:
                        lex >> parbreak_is_newline;
                        break;
@@ -1280,6 +1286,7 @@ void Layout::write(ostream & os) const
                os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
        os << "\tFreeSpacing " << free_spacing << '\n';
        os << "\tPassThru " << pass_thru << '\n';
+       os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
        os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
        switch (spacing.getSpace()) {
        case Spacing::Double:
diff --git a/src/Layout.h b/src/Layout.h
index 2da831e..9f98f0a 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -285,6 +285,8 @@ public:
        bool free_spacing;
        ///
        bool pass_thru;
+       /// Individual chars to be passed verbatim
+       docstring pass_thru_chars;
        ///
        bool parbreak_is_newline;
        /// show this in toc
diff --git a/src/OutputParams.h b/src/OutputParams.h
index 8663c17..e5e9ad0 100644
--- a/src/OutputParams.h
+++ b/src/OutputParams.h
@@ -254,6 +254,9 @@ public:
        /// Should we output verbatim or escape LaTeX's special chars?
        bool pass_thru;
 
+       /// Should we output verbatim specific chars?
+       docstring pass_thru_chars;
+
        /// Should we output captions?
        bool html_disable_captions;
 
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 906a069..35e86a1 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1139,7 +1139,13 @@ void Paragraph::Private::latexSpecialChar(otexstream & 
os,
        char_type const c = (runparams.use_polyglossia) ?
                owner_->getUChar(bparams, i) : text_[i];
 
-       if (style.pass_thru || runparams.pass_thru) {
+       // Characters that are requested ny layout/insetlayout to be handled 
verbatim
+       vector<docstring> pass_thru_chars = 
getVectorFromString(style.pass_thru_chars);
+       vector<docstring> il_pass_thru_chars = 
getVectorFromString(runparams.pass_thru_chars);
+       pass_thru_chars.insert(pass_thru_chars.end(), 
il_pass_thru_chars.begin(), il_pass_thru_chars.end());
+
+       if (style.pass_thru || runparams.pass_thru
+           || (std::find(pass_thru_chars.begin(), pass_thru_chars.end(), 
docstring(1, c)) != pass_thru_chars.end())) {
                if (c != '\0') {
                        Encoding const * const enc = runparams.encoding;
                        if (enc && !enc->encodable(c))
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index 6b30f5a..6e081d9 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -117,6 +117,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & 
tclass)
                IL_MULTIPAR,
                IL_NEEDPROTECT,
                IL_PASSTHRU,
+               IL_PASSTHRU_CHARS,
                IL_PARBREAKISNEWLINE,
                IL_PREAMBLE,
                IL_REQUIRES,
@@ -171,6 +172,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & 
tclass)
                { "obsoletedby", IL_OBSOLETEDBY },
                { "parbreakisnewline", IL_PARBREAKISNEWLINE },
                { "passthru", IL_PASSTHRU },
+               { "passthruchars", IL_PASSTHRU_CHARS },
                { "preamble", IL_PREAMBLE },
                { "refprefix", IL_REFPREFIX },
                { "requires", IL_REQUIRES },
@@ -296,6 +298,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & 
tclass)
                case IL_PASSTHRU:
                        lex >> passthru_;
                        break;
+               case IL_PASSTHRU_CHARS:
+                       lex >> passthru_chars_;
+                       break;
                case IL_PARBREAKISNEWLINE:
                        lex >> parbreakisnewline_;
                        break;
diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h
index d2e6458..9589fad 100644
--- a/src/insets/InsetLayout.h
+++ b/src/insets/InsetLayout.h
@@ -156,6 +156,8 @@ public:
        ///
        bool isPassThru() const { return passthru_; }
        ///
+       docstring passThruChars() const { return passthru_chars_; }
+       ///
        bool parbreakIsNewline() const { return parbreakisnewline_; }
        ///
        bool isNeedProtect() const { return needprotect_; }
@@ -262,6 +264,8 @@ private:
        ///
        bool passthru_;
        ///
+       docstring passthru_chars_;
+       ///
        bool parbreakisnewline_;
        ///
        bool freespacing_;
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 7a67123..43749f9 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -478,6 +478,11 @@ void InsetText::latex(otexstream & os, OutputParams const 
& runparams) const
                rp.pass_thru = true;
        if (il.isNeedProtect())
                rp.moving_arg = true;
+       if (!il.passThruChars().empty()) {
+               if (!rp.pass_thru_chars.empty())
+                       rp.pass_thru_chars += ",";
+               rp.pass_thru_chars += il.passThruChars();
+       }
        rp.par_begin = 0;
        rp.par_end = paragraphs().size();
 

Reply via email to