From 1ed70d10fdfa64186c1b640bc83158d94fd1f2f3 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 21 Dec 2016 15:17:30 +0100 Subject: [PATCH] Add "Plain" quotation mark style File format change --- development/FORMAT | 7 ++ lib/languages | 1 + lib/lyx2lyx/lyx_2_3.py | 31 +++++++- lib/ui/stdmenus.inc | 4 +- src/BufferParams.cpp | 3 +- src/LaTeXFeatures.cpp | 33 +++++++++ src/LyXAction.cpp | 1 + src/frontends/qt4/GuiDocument.cpp | 2 + src/frontends/qt4/Menus.cpp | 8 +++ src/insets/InsetQuotes.cpp | 115 ++++++++++++++++++++---------- src/insets/InsetQuotes.h | 4 +- src/tex2lyx/TODO.txt | 3 + src/version.h | 4 +- 13 files changed, 172 insertions(+), 44 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 999ff2a902..9cc37edd84 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,13 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2016-12-21 Jürgen Spitzmüller + * Format incremented to 520: Introduce plain quote style: + \begin_inset Quotes qls => \textquotesingle + \begin_inset Quotes qld => \textquotesingle + \begin_inset Quotes qrs => \textquotedbl + \begin_inset Quotes qrd => \textquotedbl + 2016-12-20 Jürgen Spitzmüller * Format incremented to 519: rename \quotes_language to \quotes_style. diff --git a/lib/languages b/lib/languages index 9175812050..2df8f0a824 100644 --- a/lib/languages +++ b/lib/languages @@ -49,6 +49,7 @@ # - german: ,,text`` ,text` (99/66) # - polish: ,,text'' ,text' (99/99) # - swedish: ''text'' 'text' (99_99) +# - plain: "text" 'text' (straight non-typographical quotes) # Note that the option names have been selected (rather arbitrarily) # because the respective styles are common in the respective countries. # Of course this does not imply any fixed relation to those countries. diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py index 35975bce8e..6949364140 100644 --- a/lib/lyx2lyx/lyx_2_3.py +++ b/lib/lyx2lyx/lyx_2_3.py @@ -666,6 +666,33 @@ def revert_quotestyle(document): document.header[i] = "\\quotes_language " + val +def revert_plainquote(document): + " Revert plain quote inset " + + # First, revert style setting + i = find_token(document.header, "\\quotes_style plain", 0) + if i != -1: + document.header[i] = "\\quotes_style english" + + # now the insets + i = 0 + j = 0 + while True: + k = find_token(document.body, '\\begin_inset Quotes q', i) + if k == -1: + return + l = find_end_of_inset(document.body, k) + if l == -1: + document.warning("Malformed LyX document: Can't find end of Quote inset at line " + str(k)) + i = k + continue + replace = "\"" + if document.body[k].endswith("s"): + replace = "'" + document.body[k:l+1] = [replace] + i = l + + ## # Conversion hub # @@ -682,10 +709,12 @@ convert = [ [516, [convert_inputenc]], [517, []], [518, [convert_iopart]], - [519, [convert_quotestyle]] + [519, [convert_quotestyle]], + [520, []] ] revert = [ + [519, [revert_plainquote]], [518, [revert_quotestyle]], [517, [revert_iopart]], [516, [revert_quotes]], diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 3404fa8afc..47e7b61e81 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -400,8 +400,8 @@ Menuset Item "Symbols...|b" "dialog-show symbols" Item "Ellipsis|i" "specialchar-insert dots" Item "End of Sentence|E" "specialchar-insert end-of-sentence" - Item "Ordinary Quote|Q" "self-insert \"" - Item "Single Quote|S" "quote-insert single" + Item "Plain Quotation Mark|Q" "quote-insert double auto plain" + Item "Single Quotation Mark|S" "quote-insert single" Item "Protected Hyphen|y" "specialchar-insert nobreakdash" Item "Breakable Slash|a" "specialchar-insert slash" Item "Visible Space|V" "space-insert visible" diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 487f0341b3..00cbbedfe8 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -72,7 +72,7 @@ static char const * const string_paragraph_separation[] = { static char const * const string_quotes_style[] = { - "english", "swedish", "german", "polish", "french", "danish", "" + "english", "swedish", "german", "polish", "french", "danish", "plain", "" }; @@ -140,6 +140,7 @@ QuotesStyleTranslator const init_quotesstyletranslator() translator.addPair(string_quotes_style[3], InsetQuotes::PolishQuotes); translator.addPair(string_quotes_style[4], InsetQuotes::FrenchQuotes); translator.addPair(string_quotes_style[5], InsetQuotes::DanishQuotes); + translator.addPair(string_quotes_style[6], InsetQuotes::PlainQuotes); return translator; } diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 777924c5a2..4c993b6f7b 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -118,6 +118,25 @@ static docstring const guilsinglright_def = from_ascii( " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n" "}"); +static docstring const textquotedbl_def = from_ascii( + "\\DeclareTextSymbolDefault{\\textquotedbl}{T1}"); + +static docstring const textquotedblp_xetex_def = from_ascii( + "\\providecommand\\textquotedblplain{%\n" + " \\bgroup\\addfontfeatures{Mapping=}\\textquotedbl\\egroup}"); + +static docstring const textquotedblp_luatex_def = from_ascii( + "\\providecommand\\textquotedblplain{%\n" + " \\bgroup\\addfontfeatures{RawFeature=-tlig}\\textquotedbl\\egroup}"); + +static docstring const textquotesinglep_xetex_def = from_ascii( + "\\providecommand\\textquotesingleplain{%\n" + " \\bgroup\\addfontfeatures{Mapping=}\\textquotesingle\\egroup}"); + +static docstring const textquotesinglep_luatex_def = from_ascii( + "\\providecommand\\textquotesingleplain{%\n" + " \\bgroup\\addfontfeatures{RawFeature=-tlig}\\textquotesingle\\egroup}"); + static docstring const paragraphleftindent_def = from_ascii( "\\newenvironment{LyXParagraphLeftIndent}[1]%\n" "{\n" @@ -1373,6 +1392,20 @@ TexString LaTeXFeatures::getMacros() const macros << guillemotleft_def << '\n'; if (mustProvide("guillemotright")) macros << guillemotright_def << '\n'; + if (mustProvide("textquotedbl")) + macros << textquotedbl_def << '\n'; + if (mustProvide("textquotesinglep")) { + if (runparams_.flavor == OutputParams::XETEX) + macros << textquotesinglep_xetex_def << '\n'; + else + macros << textquotesinglep_luatex_def << '\n'; + } + if (mustProvide("textquotedblp")) { + if (runparams_.flavor == OutputParams::XETEX) + macros << textquotedblp_xetex_def << '\n'; + else + macros << textquotedblp_luatex_def << '\n'; + } // Math mode if (mustProvide("binom") && !isRequired("amsmath")) diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 9b8ae16504..63b4a69bee 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -414,6 +414,7 @@ void LyXAction::init() * 'polish' for ,,Polish'' quote style * 'french' for <> quote style * 'danish' for >>Danish<< quote style + * 'plain' for "Plain" quote style * If no quote style is specified, the document-wide will be used. * \endvar */ diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 97d4d205eb..33abb3abcc 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -1079,6 +1079,8 @@ GuiDocument::GuiDocument(GuiView & lv) qt_("<>"), InsetQuotes::FrenchQuotes); langModule->quoteStyleCO->addItem( qt_(">>text<<"), InsetQuotes::DanishQuotes); + langModule->quoteStyleCO->addItem( + qt_("\"text\""), InsetQuotes::PlainQuotes); langModule->languagePackageCO->addItem( qt_("Default"), toqstr("default")); diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 5a7e8e09aa..25467dbf8f 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1681,6 +1681,7 @@ void MenuDefinition::expandQuotes(BufferView const * bv) MenuDefinition pqs; MenuDefinition fqs; MenuDefinition aqs; + MenuDefinition qqs; for (; qq != end; ++qq) { docstring const style = from_ascii(qq->first); FuncRequest const cmd = FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype ") + style); @@ -1700,6 +1701,8 @@ void MenuDefinition::expandQuotes(BufferView const * bv) fqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd)); else if (prefixIs(style, 'a') && !prefixIs(qtype, "a")) aqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd)); + else if (prefixIs(style, 'q') && !prefixIs(qtype, "q")) + qqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd)); } if (!eqs.empty()) { @@ -1732,6 +1735,11 @@ void MenuDefinition::expandQuotes(BufferView const * bv) item.setSubmenu(aqs); add(item); } + if (!qqs.empty()) { + MenuItem item(MenuItem::Submenu, qt_("\"text\"")); + item.setSubmenu(qqs); + add(item); + } } diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index 768c6c7212..cc3e3e051e 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -53,57 +53,58 @@ namespace { * p ,,polish'' * f <> * a >>danish<< + * q "plain" */ -char const * const style_char = "esgpfa"; +char const * const style_char = "esgpfaq"; char const * const side_char = "lr" ; char const * const level_char = "sd"; // List of known quote chars -char const * const quote_char = ",'`<>"; +char const * const quote_char = ",'`<>\""; // Unicode characters needed by each quote type -char_type const display_quote_char[2][5] = { - { 0x201a, 0x2019, 0x2018, 0x2039, 0x203a}, - { 0x201e, 0x201d, 0x201c, 0x00ab, 0x00bb} +char_type const display_quote_char[2][6] = { + { 0x201a, 0x2019, 0x2018, 0x2039, 0x203a, 0x0027}, + { 0x201e, 0x201d, 0x201c, 0x00ab, 0x00bb, 0x0022} }; // Index of chars used for the quote. Index is [side, style] -int quote_index[2][6] = { - { 2, 1, 0, 0, 3, 4 }, // "'',,<>" - { 1, 1, 2, 1, 4, 3 } // "`'`'><" +int quote_index[2][7] = { + { 2, 1, 0, 0, 3, 4, 5 }, // { ` ' , , < > \" } + { 1, 1, 2, 1, 4, 3, 5 } // { ' ' ` ' > < \" } }; // Corresponding LaTeX code, for double and single quotes. -char const * const latex_quote_t1[2][5] = { +char const * const latex_quote_t1[2][6] = { { "\\quotesinglbase", "'", "`", - "\\guilsinglleft", "\\guilsinglright" }, - { ",,", "''", "``", "<<", ">>" } + "\\guilsinglleft", "\\guilsinglright", "\\textquotesingle" }, + { ",,", "''", "``", "<<", ">>", "\\textquotedbl" } }; -char const * const latex_quote_ot1[2][5] = { +char const * const latex_quote_ot1[2][6] = { { "\\quotesinglbase", "'", "`", - "\\guilsinglleft", "\\guilsinglright" }, + "\\guilsinglleft", "\\guilsinglright", "\\textquotesingle" }, { "\\quotedblbase", "''", "``", - "\\guillemotleft", "\\guillemotright" } + "\\guillemotleft", "\\guillemotright", "\\textquotedbl" } }; -char const * const latex_quote_noligatures[2][5] = { +char const * const latex_quote_noligatures[2][6] = { { "\\quotesinglbase", "\\textquoteleft", "\\textquoteright", - "\\guilsinglleft", "\\guilsinglright" }, + "\\guilsinglleft", "\\guilsinglright", "\\textquotesingle" }, { "\\quotedblbase", "\\textquotedblleft", "\\textquotedblright", - "\\guillemotleft", "\\guillemotright" } + "\\guillemotleft", "\\guillemotright", "\\textquotedbl" } }; -char const * const latex_quote_babel[2][5] = { - { "\\glq", "'", "`", "\\flq", "\\frq" }, - { "\\glqq", "''", "``", "\\flqq", "\\frqq" } +char const * const latex_quote_babel[2][6] = { + { "\\glq", "'", "`", "\\flq", "\\frq", "\\textquotesingle" }, + { "\\glqq", "''", "``", "\\flqq", "\\frqq", "\\textquotedbl" } }; -char const * const html_quote[2][5] = { +char const * const html_quote[2][6] = { { "‚", "’", "‘", - "‹", "›" }, - { "„", "”", "“", "«", "»" } + "‹", "›", "'" }, + { "„", "”", "“", "«", "»", """ } }; } // namespace anon @@ -171,13 +172,13 @@ void InsetQuotes::parseString(string const & s, bool const allow_wildcards) // '.' wildcard means: keep current stylee if (!allow_wildcards || str[0] != '.') { - for (i = 0; i < 6; ++i) { + for (i = 0; i < 7; ++i) { if (str[0] == style_char[i]) { style_ = QuoteStyle(i); break; } } - if (i >= 6) { + if (i >= 7) { lyxerr << "ERROR (InsetQuotes::InsetQuotes):" " bad style specification." << endl; style_ = EnglishQuotes; @@ -232,6 +233,8 @@ InsetQuotes::QuoteStyle InsetQuotes::getStyle(string const & s) qs = FrenchQuotes; else if (s == "danish") qs = DanishQuotes; + else if (s == "plain") + qs = PlainQuotes; return qs; } @@ -248,7 +251,7 @@ map InsetQuotes::getTypes() const string type; // get all quote types - for (sty = 0; sty < 6; ++sty) { + for (sty = 0; sty < 7; ++sty) { style = QuoteStyle(sty); for (sid = 0; sid < 2; ++sid) { side = QuoteSide(sid); @@ -276,7 +279,6 @@ docstring InsetQuotes::displayString() const docstring retdisp = docstring(1, display_quote_char[level_][index]); // in French, thin spaces are added inside double guillemets - // FIXME: this should be done by a separate quote type. if (prefixIs(context_lang_, "fr") && level_ == DoubleQuotes && style_ == FrenchQuotes) { // THIN SPACE (U+2009) @@ -388,6 +390,12 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const // In pass-thru context, we output plain quotes if (runparams.pass_thru) qstr = (level_ == DoubleQuotes) ? from_ascii("\"") : from_ascii("'"); + else if (style_ == PlainQuotes && runparams.isFullUnicode()) { + // For XeTeX and LuaTeX,we need to disable mapping to get straight + // quotes. We define our own commands that do this + qstr = (level_ == DoubleQuotes) ? + from_ascii("\\textquotedblplain") : from_ascii("\\textquotesingleplain"); + } else if (runparams.use_polyglossia) { // For polyglossia, we directly output the respective unicode chars // (spacing and kerning is then handled respectively) @@ -459,7 +467,6 @@ docstring InsetQuotes::getQuoteEntity() const { const int quoteind = quote_index[side_][style_]; docstring res = from_ascii(html_quote[level_][quoteind]); // in French, thin spaces are added inside double guillemets - // FIXME: this should be done by a separate quote type. if (prefixIs(context_lang_, "fr") && level_ == DoubleQuotes && style_ == FrenchQuotes) { // THIN SPACE (U+2009) @@ -517,22 +524,56 @@ void InsetQuotes::validate(LaTeXFeatures & features) const #else if (!features.useBabel() #endif - && !features.usePolyglossia() && fontenc_ != "T1") { + && !features.runparams().isFullUnicode() && fontenc_ != "T1") { if (level_ == SingleQuotes) switch (type) { - case ',': features.require("quotesinglbase"); break; - case '<': features.require("guilsinglleft"); break; - case '>': features.require("guilsinglright"); break; - default: break; + case ',': + features.require("quotesinglbase"); + break; + case '<': + features.require("guilsinglleft"); + break; + case '>': + features.require("guilsinglright"); + break; + default: + break; } else switch (type) { - case ',': features.require("quotedblbase"); break; - case '<': features.require("guillemotleft"); break; - case '>': features.require("guillemotright"); break; - default: break; + case ',': + features.require("quotedblbase"); + break; + case '<': + features.require("guillemotleft"); + break; + case '>': + features.require("guillemotright"); + break; + default: + break; } } + if (type == '"') { + switch (level_) { + case SingleQuotes: { + if (features.runparams().isFullUnicode()) + features.require("textquotesinglep"); + else + features.require("textcomp"); + break; + } + case DoubleQuotes: { + if (features.runparams().isFullUnicode()) + features.require("textquotedblp"); + else if (fontenc_ != "T1") + features.require("textquotedbl"); + break; + default: + break; + } + } + } } diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h index 0d50c1299c..57f3fef1c2 100644 --- a/src/insets/InsetQuotes.h +++ b/src/insets/InsetQuotes.h @@ -38,7 +38,9 @@ public: /// FrenchQuotes, /// - DanishQuotes + DanishQuotes, + /// + PlainQuotes }; /// enum QuoteSide { diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 233950bf0c..46353e8225 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -83,6 +83,9 @@ Format LaTeX feature LyX feature \twocolumn[]{}{} Layout Twocolumn, InsetArgument \item[]<> InsetArgument \begin{enumerate|itemize|...}[] InsetArgument +520 Plain InsetQuote Style: + \textquotesingle \begin_inset Quotes qls, \begin_inset Quotes qrs + \textquotedbl \begin_inset Quotes qld, \begin_inset Quotes qrd General diff --git a/src/version.h b/src/version.h index fecef7b2de..053c203d3d 100644 --- a/src/version.h +++ b/src/version.h @@ -32,8 +32,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 519 // spitz: \\quotes_language -> \\quotes_style -#define LYX_FORMAT_TEX2LYX 519 +#define LYX_FORMAT_LYX 520 // spitz: plain quotes style +#define LYX_FORMAT_TEX2LYX 520 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER -- 2.39.5