Add "Plain" quotation mark style

File format change
This commit is contained in:
Juergen Spitzmueller 2016-12-21 15:17:30 +01:00
parent 9aec8fd5e8
commit 1ed70d10fd
13 changed files with 172 additions and 44 deletions

View File

@ -11,6 +11,13 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
2016-12-21 Jürgen Spitzmüller <spitz@lyx.org>
* 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 <spitz@lyx.org>
* Format incremented to 519: rename \quotes_language to \quotes_style.

View File

@ -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.

View File

@ -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]],

View File

@ -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"

View File

@ -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;
}

View File

@ -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"))

View File

@ -414,6 +414,7 @@ void LyXAction::init()
* 'polish' for ,,Polish'' quote style
* 'french' for <<French>> 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
*/

View File

@ -1079,6 +1079,8 @@ GuiDocument::GuiDocument(GuiView & lv)
qt_("<<text>>"), InsetQuotes::FrenchQuotes);
langModule->quoteStyleCO->addItem(
qt_(">>text<<"), InsetQuotes::DanishQuotes);
langModule->quoteStyleCO->addItem(
qt_("\"text\""), InsetQuotes::PlainQuotes);
langModule->languagePackageCO->addItem(
qt_("Default"), toqstr("default"));

View File

@ -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);
}
}

View File

@ -53,57 +53,58 @@ namespace {
* p ,,polish''
* f <<french>>
* 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] = {
{ "&sbquo;", "&rsquo;", "&lsquo;",
"&lsaquo;", "&rsaquo;" },
{ "&bdquo;", "&rdquo;", "&ldquo;", "&laquo;", "&raquo;" }
"&lsaquo;", "&rsaquo;", "&#x27;" },
{ "&bdquo;", "&rdquo;", "&ldquo;", "&laquo;", "&raquo;", "&quot;" }
};
} // 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<string, docstring> 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;
}
}
}
}

View File

@ -38,7 +38,9 @@ public:
///
FrenchQuotes,
///
DanishQuotes
DanishQuotes,
///
PlainQuotes
};
///
enum QuoteSide {

View File

@ -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

View File

@ -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