\TestPackage{chicago}
\TestPackage{color} % this one should be there if graphics.sty is there.
\TestPackage{covington}
+\TestPackage{cprotect}
\TestPackage{csquotes}
\TestPackage[koi8-r.def]{cyrillic}
\TestPackage{dvipost}
not
\emph default
whether the command should itself be protected.) Default is false.
+\change_inserted -712698321 1523633958
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted -712698321 1523634088
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1523633961
+NeedCProtect
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1523633958
+
+\emph on
+0
+\end_layout
+
+\end_inset
+
+,
+\begin_inset space \thinspace{}
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1523633958
+1
+\end_layout
+
+\end_inset
+
+] This causes macros that contain this inset to be protected with
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1523634038
+
+\backslash
+cprotect
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ (cf.
+ package
+\family sans
+cprotect
+\family default
+) if necessary and thus allows (some) verbatim stuff in macros.
+ Default is false.
+\change_unchanged
+
\end_layout
\begin_layout Description
.
\end_layout
+\begin_layout Subsection
+cprotect
+\end_layout
+
+\begin_layout Description
+Found:
+\begin_inset Info
+type "package"
+arg "cprotect"
+\end_inset
+
+
+\end_layout
+
+\begin_layout Description
+CTAN:
+\family typewriter
+macros/latex/contrib/cprotect/
+\end_layout
+
+\begin_layout Description
+Notes: The package
+\family sans
+cprotect
+\family default
+ is used to allow (some) verbatim stuff in macros.
+\end_layout
+
\begin_layout Subsection
CJKutf8
\end_layout
EndHTMLStyle
AddToToc note
IsTocCaption true
+ NeedCProtect true
End
PassThru true
FreeSpacing true
ForceLTR true
+ NeedCProtect true
Font
Family Typewriter
Color urltext
// note that the package order here will be the same in the LaTeX-output
"array",
"verbatim",
+ "cprotect",
"longtable",
"rotating",
"latexsym",
void Paragraph::validate(LaTeXFeatures & features) const
{
d->validate(features);
+ if (needsCProtection())
+ features.require("cprotect");
}
}
+bool Paragraph::needsCProtection() const
+{
+ pos_type size = d->text_.size();
+ for (pos_type i = 0; i < size; ++i)
+ if (isInset(i))
+ return getInset(i)->needsCProtection();
+
+ return false;
+}
+
+
FontSpan const & Paragraph::getSpellRange(pos_type pos) const
{
return d->speller_state_.getRange(pos);
/// True if the element at this point is a hard hyphen or a apostrophe
/// If it is enclosed by spaces return false
bool isHardHyphenOrApostrophe(pos_type pos) const;
+ /// Return true if this paragraph has verbatim content that needs to be
+ /// protected by \cprotect
+ bool needsCProtection() const;
/// returns true if at least one line break or line separator has been deleted
/// at the beginning of the paragraph (either physically or logically)
/// reject the changes within the inset
virtual void rejectChanges() {}
+ ///
+ virtual bool needsCProtection() const { return false; }
+
///
virtual ColorCode backgroundColor(PainterInfo const &) const;
///
htmlisblock_(true), multipar_(true), custompars_(true),
forceplain_(false), passthru_(false), parbreakisnewline_(false),
freespacing_(false), keepempty_(false), forceltr_(false),
- forceownlines_(false), needprotect_(false), intoc_(false),
- spellcheck_(true), resetsfont_(false), display_(true),
+ forceownlines_(false), needprotect_(false), needcprotect_(false),
+ intoc_(false), spellcheck_(true), resetsfont_(false), display_(true),
forcelocalfontswitch_(false), add_to_toc_(false), is_toc_caption_(false)
{
labelfont_.setColor(Color_error);
IL_OBSOLETEDBY,
IL_KEEPEMPTY,
IL_MULTIPAR,
+ IL_NEEDCPROTECT,
IL_NEEDPROTECT,
IL_PASSTHRU,
IL_PASSTHRU_CHARS,
{ "leftdelim", IL_LEFTDELIM },
{ "lyxtype", IL_LYXTYPE },
{ "multipar", IL_MULTIPAR },
+ { "needcprotect", IL_NEEDCPROTECT },
{ "needprotect", IL_NEEDPROTECT },
{ "obsoletedby", IL_OBSOLETEDBY },
{ "parbreakisnewline", IL_PARBREAKISNEWLINE },
case IL_NEEDPROTECT:
lex >> needprotect_;
break;
+ case IL_NEEDCPROTECT:
+ lex >> needcprotect_;
+ break;
case IL_CONTENTASLABEL:
lex >> contentaslabel_;
break;
///
bool isNeedProtect() const { return needprotect_; }
///
+ bool needsCProtect() const { return needcprotect_; }
+ ///
bool isFreeSpacing() const { return freespacing_; }
///
bool isKeepEmpty() const { return keepempty_; }
bool forceownlines_;
///
bool needprotect_;
+ ///
+ bool needcprotect_;
/// should the contents be written to TOC strings?
bool intoc_;
/// check spelling of this inset?
// FIXME UNICODE
// FIXME \protect should only be used for fragile
// commands, but we do not provide this information yet.
- if (runparams.moving_arg)
+ if (hasCProtectContent())
+ os << "\\cprotect";
+ else if (runparams.moving_arg)
os << "\\protect";
os << '\\' << from_utf8(il.latexname());
if (!il.latexargs().empty())
}
+bool InsetText::hasCProtectContent() const
+{
+ ParagraphList const & pars = paragraphs();
+ pit_type pend = paragraphs().size();
+ for (pit_type pit = 0; pit != pend; ++pit) {
+ Paragraph const & par = pars[pit];
+ if (par.needsCProtection())
+ return true;
+ }
+ return false;
+}
+
+
bool InsetText::insetAllowed(InsetCode code) const
{
switch (code) {
return static_cast<InsetText::XHTMLOptions>((int)a1 | (int)a2);
}
+
+bool InsetText::needsCProtection() const
+{
+ if (!getLayout().needsCProtect())
+ return false;
+
+ // Environments need cprotection regardless the content
+ if (getLayout().latextype() == InsetLayout::ENVIRONMENT)
+ return true;
+
+ // Commands need cprotection if they contain specific chars
+ int const nchars_escape = 9;
+ static char_type const chars_escape[nchars_escape] = {
+ '&', '_', '$', '%', '#', '^', '{', '}', '\\'};
+
+ ParagraphList const & pars = paragraphs();
+ pit_type pend = paragraphs().size();
+
+ for (pit_type pit = 0; pit != pend; ++pit) {
+ Paragraph const & par = pars[pit];
+ if (par.needsCProtection())
+ return true;
+ docstring const pars = par.asString();
+ for (int k = 0; k < nchars_escape; k++) {
+ if (contains(pars, chars_escape[k]))
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace lyx
///
bool confirmDeletion() const { return !text().empty(); }
+ ///
+ bool needsCProtection() const;
+
protected:
///
void iterateForToc(DocIterator const & cdit, bool output_active,
void closeAddToTocForParagraph(pit_type start, pit_type end,
TocBackend & backend) const;
///
+ bool hasCProtectContent() const;
+ ///
bool drawFrame_;
///
ColorCode frame_color_;
{
switch (style.latextype) {
case LATEX_COMMAND:
+ if (par.needsCProtection())
+ os << "\\cprotect";
os << '\\' << from_ascii(style.latexname());
// Command arguments