mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-07 02:28:35 +00:00
Font switches in \cprotect'ed context need to be \cprotect'ed themselves
This commit is contained in:
parent
e515e7165d
commit
49e8e3567c
153
src/Font.cpp
153
src/Font.cpp
@ -228,7 +228,8 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
OutputParams const & runparams,
|
OutputParams const & runparams,
|
||||||
Font const & base,
|
Font const & base,
|
||||||
Font const & prev,
|
Font const & prev,
|
||||||
bool const & non_inherit_inset) const
|
bool const & non_inherit_inset,
|
||||||
|
bool const & needs_cprotection) const
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
@ -237,13 +238,28 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
&& language()->lang() != base.language()->lang()
|
&& language()->lang() != base.language()->lang()
|
||||||
&& language() != prev.language()) {
|
&& language() != prev.language()) {
|
||||||
if (!language()->polyglossia().empty()) {
|
if (!language()->polyglossia().empty()) {
|
||||||
string tmp = "\\text" + language()->polyglossia();
|
string tmp;
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
tmp += "\\begingroup\\catcode`\\^=7";
|
||||||
|
tmp += "\\cprotect";
|
||||||
|
}
|
||||||
|
tmp += "\\text" + language()->polyglossia();
|
||||||
if (!language()->polyglossiaOpts().empty()) {
|
if (!language()->polyglossiaOpts().empty()) {
|
||||||
tmp += "[" + language()->polyglossiaOpts() + "]";
|
tmp += "[" + language()->polyglossiaOpts() + "]";
|
||||||
if (runparams.use_hyperref && runparams.moving_arg)
|
if (runparams.use_hyperref && runparams.moving_arg) {
|
||||||
// We need to strip the command for
|
// We need to strip the command for
|
||||||
// the pdf string, see #11813
|
// the pdf string, see #11813
|
||||||
tmp = "\\texorpdfstring{" + tmp + "}{}";
|
string tmpp;
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
tmpp = "\\cprotect";
|
||||||
|
}
|
||||||
|
tmp = tmpp + "\\texorpdfstring{" + tmp + "}{}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tmp += "{";
|
tmp += "{";
|
||||||
os << from_ascii(tmp);
|
os << from_ascii(tmp);
|
||||||
@ -256,21 +272,56 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
} else if (language()->babel() != base.language()->babel() &&
|
} else if (language()->babel() != base.language()->babel() &&
|
||||||
language() != prev.language()) {
|
language() != prev.language()) {
|
||||||
if (language()->lang() == "farsi") {
|
if (language()->lang() == "farsi") {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\textFR{";
|
os << "\\textFR{";
|
||||||
count += 8;
|
count += 8;
|
||||||
} else if (!isRightToLeft() &&
|
} else if (!isRightToLeft() &&
|
||||||
base.language()->lang() == "farsi") {
|
base.language()->lang() == "farsi") {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\textLR{";
|
os << "\\textLR{";
|
||||||
count += 8;
|
count += 8;
|
||||||
} else if (language()->lang() == "arabic_arabi") {
|
} else if (language()->lang() == "arabic_arabi") {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\textAR{";
|
os << "\\textAR{";
|
||||||
count += 8;
|
count += 8;
|
||||||
} else if (!isRightToLeft() &&
|
} else if (!isRightToLeft() &&
|
||||||
base.language()->lang() == "arabic_arabi") {
|
base.language()->lang() == "arabic_arabi") {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\textLR{";
|
os << "\\textLR{";
|
||||||
count += 8;
|
count += 8;
|
||||||
// currently the remaining RTL languages are arabic_arabtex and hebrew
|
// currently the remaining RTL languages are arabic_arabtex and hebrew
|
||||||
} else if (isRightToLeft() != prev.isRightToLeft()) {
|
} else if (isRightToLeft() != prev.isRightToLeft()) {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
if (isRightToLeft()) {
|
if (isRightToLeft()) {
|
||||||
os << "\\R{";
|
os << "\\R{";
|
||||||
count += 3;
|
count += 3;
|
||||||
@ -282,6 +333,13 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
string const tmp =
|
string const tmp =
|
||||||
subst(lyxrc.language_command_local,
|
subst(lyxrc.language_command_local,
|
||||||
"$$lang", language()->babel());
|
"$$lang", language()->babel());
|
||||||
|
if (needs_cprotection && !prefixIs(tmp, "\\begin{")) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << from_ascii(tmp);
|
os << from_ascii(tmp);
|
||||||
count += tmp.length();
|
count += tmp.length();
|
||||||
if (!lyxrc.language_command_end.empty())
|
if (!lyxrc.language_command_end.empty())
|
||||||
@ -321,6 +379,13 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
os << '\\' << LaTeXFamilySwitchNames[f.family()] << termcmd;
|
os << '\\' << LaTeXFamilySwitchNames[f.family()] << termcmd;
|
||||||
count += strlen(LaTeXFamilySwitchNames[f.family()]) + 1;
|
count += strlen(LaTeXFamilySwitchNames[f.family()]) + 1;
|
||||||
} else {
|
} else {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << '\\'
|
os << '\\'
|
||||||
<< LaTeXFamilyCommandNames[f.family()]
|
<< LaTeXFamilyCommandNames[f.family()]
|
||||||
<< '{';
|
<< '{';
|
||||||
@ -334,6 +399,13 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
os << '\\' << LaTeXSeriesSwitchNames[f.series()] << termcmd;
|
os << '\\' << LaTeXSeriesSwitchNames[f.series()] << termcmd;
|
||||||
count += strlen(LaTeXSeriesSwitchNames[f.series()]) + 1;
|
count += strlen(LaTeXSeriesSwitchNames[f.series()]) + 1;
|
||||||
} else {
|
} else {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << '\\'
|
os << '\\'
|
||||||
<< LaTeXSeriesCommandNames[f.series()]
|
<< LaTeXSeriesCommandNames[f.series()]
|
||||||
<< '{';
|
<< '{';
|
||||||
@ -347,6 +419,13 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
os << '\\' << LaTeXShapeSwitchNames[f.shape()] << termcmd;
|
os << '\\' << LaTeXShapeSwitchNames[f.shape()] << termcmd;
|
||||||
count += strlen(LaTeXShapeSwitchNames[f.shape()]) + 1;
|
count += strlen(LaTeXShapeSwitchNames[f.shape()]) + 1;
|
||||||
} else {
|
} else {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << '\\'
|
os << '\\'
|
||||||
<< LaTeXShapeCommandNames[f.shape()]
|
<< LaTeXShapeCommandNames[f.shape()]
|
||||||
<< '{';
|
<< '{';
|
||||||
@ -359,6 +438,13 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
os << '}';
|
os << '}';
|
||||||
++count;
|
++count;
|
||||||
} else if (f.color() != Color_none) {
|
} else if (f.color() != Color_none) {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\textcolor{"
|
os << "\\textcolor{"
|
||||||
<< from_ascii(lcolor.getLaTeXName(f.color()))
|
<< from_ascii(lcolor.getLaTeXName(f.color()))
|
||||||
<< "}{";
|
<< "}{";
|
||||||
@ -396,11 +482,25 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (f.emph() == FONT_ON) {
|
if (f.emph() == FONT_ON) {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\emph{";
|
os << "\\emph{";
|
||||||
count += 6;
|
count += 6;
|
||||||
}
|
}
|
||||||
// \noun{} is a LyX special macro
|
// \noun{} is a LyX special macro
|
||||||
if (f.noun() == FONT_ON) {
|
if (f.noun() == FONT_ON) {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\noun{";
|
os << "\\noun{";
|
||||||
count += 6;
|
count += 6;
|
||||||
}
|
}
|
||||||
@ -408,23 +508,51 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
// because ulem puts every nested group or macro in a box,
|
// because ulem puts every nested group or macro in a box,
|
||||||
// which prevents linebreaks (#8424, #8733)
|
// which prevents linebreaks (#8424, #8733)
|
||||||
if (f.underbar() == FONT_ON) {
|
if (f.underbar() == FONT_ON) {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\uline{";
|
os << "\\uline{";
|
||||||
count += 10;
|
count += 7;
|
||||||
++runparams.inulemcmd;
|
++runparams.inulemcmd;
|
||||||
}
|
}
|
||||||
if (f.uuline() == FONT_ON) {
|
if (f.uuline() == FONT_ON) {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\uuline{";
|
os << "\\uuline{";
|
||||||
count += 11;
|
count += 8;
|
||||||
++runparams.inulemcmd;
|
++runparams.inulemcmd;
|
||||||
}
|
}
|
||||||
if (f.strikeout() == FONT_ON) {
|
if (f.strikeout() == FONT_ON) {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\sout{";
|
os << "\\sout{";
|
||||||
count += 9;
|
count += 6;
|
||||||
++runparams.inulemcmd;
|
++runparams.inulemcmd;
|
||||||
}
|
}
|
||||||
if (f.xout() == FONT_ON) {
|
if (f.xout() == FONT_ON) {
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\xout{";
|
os << "\\xout{";
|
||||||
count += 9;
|
count += 6;
|
||||||
++runparams.inulemcmd;
|
++runparams.inulemcmd;
|
||||||
}
|
}
|
||||||
if (f.uwave() == FONT_ON) {
|
if (f.uwave() == FONT_ON) {
|
||||||
@ -434,8 +562,15 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
|||||||
os << "\\ULdepth=1000pt";
|
os << "\\ULdepth=1000pt";
|
||||||
count += 15;
|
count += 15;
|
||||||
}
|
}
|
||||||
|
if (needs_cprotection) {
|
||||||
|
if (contains(runparams.active_chars, '^'))
|
||||||
|
// cprotect relies on ^ being on catcode 7
|
||||||
|
os << "\\begingroup\\catcode`\\^=7";
|
||||||
|
os << "\\cprotect";
|
||||||
|
count += 9;
|
||||||
|
}
|
||||||
os << "\\uwave{";
|
os << "\\uwave{";
|
||||||
count += 10;
|
count += 7;
|
||||||
++runparams.inulemcmd;
|
++runparams.inulemcmd;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
@ -76,7 +76,8 @@ public:
|
|||||||
OutputParams const & runparams,
|
OutputParams const & runparams,
|
||||||
Font const & base,
|
Font const & base,
|
||||||
Font const & prev,
|
Font const & prev,
|
||||||
bool const & non_inherit_inset = false) const;
|
bool const & non_inherit_inset = false,
|
||||||
|
bool const & needs_cprotection = false) const;
|
||||||
|
|
||||||
/** Writes the tail of the LaTeX needed to change to this font.
|
/** Writes the tail of the LaTeX needed to change to this font.
|
||||||
Returns number of chars written. Base is the font state we want
|
Returns number of chars written. Base is the font state we want
|
||||||
|
@ -1044,7 +1044,8 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
|
|||||||
|| basefont.isRightToLeft() == running_font.isRightToLeft();
|
|| basefont.isRightToLeft() == running_font.isRightToLeft();
|
||||||
unsigned int count = running_font.latexWriteStartChanges(os, bparams,
|
unsigned int count = running_font.latexWriteStartChanges(os, bparams,
|
||||||
runparams, basefont,
|
runparams, basefont,
|
||||||
running_font, true);
|
running_font, true,
|
||||||
|
owner_->needsCProtection(runparams.moving_arg));
|
||||||
column += count;
|
column += count;
|
||||||
// if any font properties were closed, update the running_font,
|
// if any font properties were closed, update the running_font,
|
||||||
// making sure, however, to leave the language as it was
|
// making sure, however, to leave the language as it was
|
||||||
@ -2659,7 +2660,8 @@ void Paragraph::latex(BufferParams const & bparams,
|
|||||||
otexstringstream ots;
|
otexstringstream ots;
|
||||||
if (!non_inherit_inset) {
|
if (!non_inherit_inset) {
|
||||||
column += current_font.latexWriteStartChanges(ots, bparams,
|
column += current_font.latexWriteStartChanges(ots, bparams,
|
||||||
runparams, basefont, last_font);
|
runparams, basefont, last_font, false,
|
||||||
|
needsCProtection(runparams.moving_arg));
|
||||||
}
|
}
|
||||||
// Check again for display math in ulem commands as a
|
// Check again for display math in ulem commands as a
|
||||||
// font change may also occur just before a math inset.
|
// font change may also occur just before a math inset.
|
||||||
|
Loading…
Reference in New Issue
Block a user