- Font font = text.getPar(sl.pit()).getFont(bp, sl.pos(),
- text.outerFont(sl.pit()));
- Encoding const * enc = font.language()->encoding();
- if (enc->name() == "inherit") {
+ Language const * lang =
+ text.getPar(sl.pit()).getFont(bp, sl.pos(),
+ text.outerFont(sl.pit())).language();
+ // If we have a custom encoding for the buffer, we only switch
+ // encoding for CJK (see output_latex::switchEncoding())
+ bool const customenc =
+ bp.inputenc != "auto" && bp.inputenc != "default";
+ Encoding const * enc =
+ (customenc && lang->encoding()->package() != Encoding::CJK)
+ ? &bp.encoding() : lang->encoding();
+
+ // Inherited encoding (latex_language) is determined by the context
+ // Look for the first outer encoding that is not itself "inherit"
+ if (lang->encoding()->name() == "inherit") {