From 70b3d3adccdda2daf9346b995575f9ee658ac5d3 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Thu, 18 Apr 2019 11:35:03 +0200 Subject: [PATCH] Add NewlineCmd InsetLayout and Argument option This allows to specific an alternative macro for newlines Fixes: #10407 --- lib/doc/Customization.lyx | 100 ++++++++++++++++++++++++++++++++- lib/doc/de/Customization.lyx | 102 ++++++++++++++++++++++++++++++++++ lib/layouts/pdfcomment.module | 12 +++- lib/scripts/layout2layout.py | 7 ++- src/Layout.cpp | 5 ++ src/Layout.h | 1 + src/OutputParams.h | 3 + src/TextClass.cpp | 2 +- src/insets/InsetArgument.cpp | 5 +- src/insets/InsetArgument.h | 2 + src/insets/InsetLayout.cpp | 8 +++ src/insets/InsetLayout.h | 4 ++ src/insets/InsetNewline.cpp | 4 +- src/insets/InsetText.cpp | 2 + 14 files changed, 250 insertions(+), 7 deletions(-) diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index 568c31bf16..07c13d8d4f 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -11995,6 +11995,56 @@ status collapsed \end_inset +\change_inserted -712698321 1555579782 + +\end_layout + +\begin_layout Itemize + +\change_inserted -712698321 1555579780 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1555579780 +NewlineCmd +\end_layout + +\end_inset + + +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1555579780 +[string] +\end_layout + +\end_inset + + Option to define a different command (from the default +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1555579780 + +\backslash + +\backslash + +\end_layout + +\end_inset + +) to be used for line breaks. + The initial backslash must not be specified. +\change_unchanged + \end_layout \begin_layout Itemize @@ -20537,7 +20587,7 @@ cprotect \begin_layout Description -\change_inserted -712698321 1552395824 +\change_inserted -712698321 1555579651 \begin_inset Flex Code status collapsed @@ -20632,6 +20682,54 @@ soul \family default commands which parse their content in complex ways. Default is false. +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1555579742 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1555579658 +NewlineCmd +\end_layout + +\end_inset + + +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1555579651 +[string] +\end_layout + +\end_inset + + Option to define a different command (from the default +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1555579742 + +\backslash + +\backslash + +\change_unchanged + +\end_layout + +\end_inset + +) to be used for line breaks. + The initial backslash must not be specified. \change_unchanged \end_layout diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx index 372acb55af..afdcfe12a8 100644 --- a/lib/doc/de/Customization.lyx +++ b/lib/doc/de/Customization.lyx @@ -10080,6 +10080,57 @@ LabelString \begin_inset Flex Code status collapsed +\begin_layout Plain Layout +NewlineCmd +\end_layout + +\end_inset + + +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout +[string] +\end_layout + +\end_inset + + erlaubt es, ein (von +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\backslash + +\backslash + +\end_layout + +\end_inset + +) abweichendes Makro für Zeilenumbrüche zu verwenden. + Das +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\backslash + +\end_layout + +\end_inset + + am Anfang des Makros müssen Sie bei der Spezifizierung nicht eingeben. + +\end_layout + +\begin_layout Itemize +\begin_inset Flex Code +status collapsed + \begin_layout Plain Layout Tooltip \end_layout @@ -18670,6 +18721,57 @@ nicht \begin_inset Flex Code status collapsed +\begin_layout Plain Layout +NewlineCmd +\end_layout + +\end_inset + + +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout +[string] +\end_layout + +\end_inset + + erlaubt es, ein (von +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\backslash + +\backslash + +\end_layout + +\end_inset + +) abweichendes Makro für Zeilenumbrüche zu verwenden. + Das +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\backslash + +\end_layout + +\end_inset + + am Anfang des Makros müssen Sie bei der Spezifizierung nicht eingeben. + +\end_layout + +\begin_layout Description +\begin_inset Flex Code +status collapsed + \begin_layout Plain Layout NoInsetLayout \end_layout diff --git a/lib/layouts/pdfcomment.module b/lib/layouts/pdfcomment.module index 38a3e9a70d..c0f9a39b97 100644 --- a/lib/layouts/pdfcomment.module +++ b/lib/layouts/pdfcomment.module @@ -8,7 +8,7 @@ # Author: Juergen Spitzmueller # Uwe Stöhr -Format 72 +Format 74 # # helper commands @@ -102,6 +102,7 @@ InsetLayout "Flex:PDF-Annotation" Size Small EndFont MultiPar false + NewlineCmd textCR Argument 1 MenuString "PDFComment Options" LabelString "Opts" @@ -125,10 +126,12 @@ InsetLayout "Flex:PDF-Markup" LabelString "PDF (Markup)" LatexName pdfmarkupcomment NeedMBoxProtect 1 + NewlineCmd "" Argument post:1 LabelString "Comment" Mandatory 1 ToolTip "Insert the comment to the marked-up text here" + NewlineCmd textCR EndArgument End @@ -136,24 +139,28 @@ InsetLayout "Flex:PDF-Freetext" CopyStyle "Flex:PDF-Margin" LabelString "PDF (Freetext)" LatexName pdffreetextcomment + NewlineCmd "" End InsetLayout "Flex:PDF-Square" CopyStyle "Flex:PDF-Margin" LabelString "PDF (Square)" LatexName pdfsquarecomment + NewlineCmd "" End InsetLayout "Flex:PDF-Circle" CopyStyle "Flex:PDF-Margin" LabelString "PDF (Circle)" LatexName pdfcirclecomment + NewlineCmd "" End InsetLayout "Flex:PDF-Line" CopyStyle "Flex:PDF-Margin" LabelString "PDF (Line)" LatexName pdflinecomment + NewlineCmd "" End InsetLayout "Flex:PDF-Sideline" @@ -162,10 +169,12 @@ InsetLayout "Flex:PDF-Sideline" LatexType environment LatexName pdfsidelinecomment MultiPar true + NewlineCmd "" Argument 2 LabelString "Comment" Mandatory 1 ToolTip "Insert the comment here" + NewlineCmd textCR EndArgument End @@ -184,6 +193,7 @@ InsetLayout "Flex:PDF-Tooltip" LabelString "PDF (Tooltip)" LatexName pdftooltip NeedMBoxProtect 0 + NewlineCmd "" LabelFont Color red Size Small diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index b89969537c..8fdc9fdf72 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -11,7 +11,7 @@ # This script will update a .layout file to current format # The latest layout format is also defined in src/TextClass.cpp -currentFormat = 73 +currentFormat = 74 # Incremented to format 4, 6 April 2007, lasgouttes @@ -245,6 +245,9 @@ currentFormat = 73 # Incremented to format 73, 18 April 2019 by spitz # New InsetLayout tag MenuString +# Incremented to format 74, 18 April 2019 by spitz +# New InsetLayout and Argument tag NewlineCmd + # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). @@ -494,7 +497,7 @@ def convert(lines, end_format): i += 1 continue - if format >= 65 and format <= 72: + if format >= 65 and format <= 73: # nothing to do. i += 1 continue diff --git a/src/Layout.cpp b/src/Layout.cpp index e4b6b3e3db..be31ccb5a1 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -1076,6 +1076,9 @@ void Layout::readArgument(Lexer & lex) } else if (tok == "decoration") { lex.next(); arg.decoration = lex.getString(); + } else if (tok == "newlinecmd") { + lex.next(); + arg.newlinecmd = lex.getString(); } else if (tok == "font") { arg.font = lyxRead(lex, arg.font); } else if (tok == "labelfont") { @@ -1146,6 +1149,8 @@ void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg os << "\t\tRequires \"" << arg.requires << "\"\n"; if (!arg.decoration.empty()) os << "\t\tDecoration \"" << arg.decoration << "\"\n"; + if (!arg.newlinecmd.empty()) + os << "\t\tNewlineCmd \"" << arg.newlinecmd << "\"\n"; if (arg.font != inherit_font) lyxWrite(os, arg.font, "Font", 2); if (arg.labelfont != inherit_font) diff --git a/src/Layout.h b/src/Layout.h index 6c4b6c01d8..fcfdc11872 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -109,6 +109,7 @@ public: ArgPassThru passthru; docstring pass_thru_chars; bool is_toc_caption; + std::string newlinecmd; }; /// typedef std::map LaTeXArgMap; diff --git a/src/OutputParams.h b/src/OutputParams.h index 5faa68e2e4..52ab2925a5 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -302,6 +302,9 @@ public: /// Should we output verbatim specific chars? docstring pass_thru_chars; + /// A specific newline macro + std::string newlinecmd; + /// Should we output captions? bool html_disable_captions; diff --git a/src/TextClass.cpp b/src/TextClass.cpp index e381060e0c..a3cadd2ff9 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -62,7 +62,7 @@ namespace lyx { // You should also run the development/tools/updatelayouts.py script, // to update the format of all of our layout files. // -int const LAYOUT_FORMAT = 73; // spitz: MenuString +int const LAYOUT_FORMAT = 74; // spitz: NewlineCmd // Layout format for the current lyx file format. Controls which format is diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index ba7031dab3..37c244d158 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -43,7 +43,7 @@ InsetArgument::InsetArgument(Buffer * buf, string const & name) : InsetCollapsible(buf), name_(name), labelstring_(docstring()), font_(inherit_font), labelfont_(inherit_font), decoration_(string()), pass_thru_context_(false), pass_thru_local_(false), pass_thru_(false), - pass_thru_chars_(docstring()), is_toc_caption_(false) + pass_thru_chars_(docstring()), is_toc_caption_(false), newline_cmd_(string()) {} @@ -118,6 +118,7 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype) labelfont_ = (*lait).second.labelfont; decoration_ = (*lait).second.decoration; pass_thru_chars_ = (*lait).second.pass_thru_chars; + newline_cmd_ = (*lait).second.newlinecmd; pass_thru_local_ = false; if (lait->second.is_toc_caption) { is_toc_caption_ = true; @@ -311,6 +312,8 @@ void InsetArgument::latexArgument(otexstream & os, OutputParams runparams = runparams_in; if (!pass_thru_chars_.empty()) runparams.pass_thru_chars += pass_thru_chars_; + if (!newline_cmd_.empty()) + runparams.newlinecmd = newline_cmd_; runparams.pass_thru = isPassThru(); InsetText::latex(ots, runparams); TexString ts = ots.release(); diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index 2bd0578f28..88af23d2f3 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -119,6 +119,8 @@ private: bool is_toc_caption_; /// The type of Toc this is the caption of, empty otherwise. std::string caption_of_toc_; + /// Specific line break macro + std::string newline_cmd_; protected: /// \name Protected functions inherited from Inset class diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 6094135024..4d6a5edfbd 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -125,6 +125,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) IL_NEEDCPROTECT, IL_NEEDMBOXPROTECT, IL_NEEDPROTECT, + IL_NEWLINE_CMD, IL_PASSTHRU, IL_PASSTHRU_CHARS, IL_PARBREAKISNEWLINE, @@ -184,6 +185,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) { "needcprotect", IL_NEEDCPROTECT }, { "needmboxprotect", IL_NEEDMBOXPROTECT }, { "needprotect", IL_NEEDPROTECT }, + { "newlinecmd", IL_NEWLINE_CMD }, { "obsoletedby", IL_OBSOLETEDBY }, { "parbreakisnewline", IL_PARBREAKISNEWLINE }, { "passthru", IL_PASSTHRU }, @@ -322,6 +324,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) case IL_PASSTHRU_CHARS: lex >> passthru_chars_; break; + case IL_NEWLINE_CMD: + lex >> newline_cmd_; + break; case IL_PARBREAKISNEWLINE: lex >> parbreakisnewline_; break; @@ -658,6 +663,9 @@ void InsetLayout::readArgument(Lexer & lex) } else if (tok == "decoration") { lex.next(); arg.decoration = lex.getString(); + } else if (tok == "newlinecmd") { + lex.next(); + arg.newlinecmd = lex.getString(); } else if (tok == "font") { arg.font = lyxRead(lex, arg.font); } else if (tok == "labelfont") { diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index dc46946897..f36afa1156 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -160,6 +160,8 @@ public: /// docstring passThruChars() const { return passthru_chars_; } /// + std::string newlineCmd() const { return newline_cmd_; } + /// bool parbreakIsNewline() const { return parbreakisnewline_; } /// bool isNeedProtect() const { return needprotect_; } @@ -283,6 +285,8 @@ private: /// docstring passthru_chars_; /// + std::string newline_cmd_; + /// bool parbreakisnewline_; /// bool freespacing_; diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index b10954d4da..b20886c830 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -146,7 +146,9 @@ void InsetNewline::latex(otexstream & os, OutputParams const & rp) const { switch (params_.kind) { case InsetNewlineParams::NEWLINE: - if (rp.inTableCell == OutputParams::PLAIN) + if (!rp.newlinecmd.empty()) + os << "\\" << rp.newlinecmd << "\n"; + else if (rp.inTableCell == OutputParams::PLAIN) os << "\\newline\n"; else os << "\\\\\n"; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 85da8dd4ec..ce69bef255 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -503,6 +503,8 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const ++rp.inulemcmd; if (!il.passThruChars().empty()) rp.pass_thru_chars += il.passThruChars(); + if (!il.newlineCmd().empty()) + rp.newlinecmd = il.newlineCmd(); rp.par_begin = 0; rp.par_end = paragraphs().size();