&& !textinset->text().isMainText()
&& inset->lyxCode() != BRANCH_CODE
&& !runparams.no_cprotect
+ && !inset->getLayout().noCProtect()
: false;
unsigned int count2 = basefont.latexWriteStartChanges(os, bparams,
rp, running_font,
{
char_type const c = owner_->getUChar(bparams, runparams, i);
- // Special case: URLs with hyperref need to escape backslash (#13012).
+ // Special case: URLs with hyperref need to escape backslash, # and % (#13012).
// Both a layout tag and a dedicated inset seem too much effort for this.
- if (c == '\\' && runparams.use_hyperref && il.latexname() == "url"
- && il.required().find("url") != il.required().end()) {
- os << "\\\\";
+ string const hr_url_escape_chars = "\\#%";
+ if (contains(hr_url_escape_chars, c) && runparams.use_hyperref && il.latexname() == "url"
+ && il.requiresFeature("url")) {
+ os << "\\";
+ os.put(c);
return;
}