我想在内listings
联代码中输入尖括号。
like ⟨this⟩
我设置listings
为(全局)以拉丁现代单声道输入。
使用以下内容
% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode
\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fontspec,hyperref,listings}
\lstset{%
basicstyle=\ttfamily\small,
breaklines=true,
language=TeX,
extendedchars=true
}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{hebrew}
\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
\lst@CCECUse \lst@ProcessLetter
^^^^27e8% Left-Pointing Angle Bracket
^^^^27e9% Right-Pointing Angle Bracket}
^^00}
\lst@RestoreCatcodes
\makeatother
\setmainfont{Latin Modern Roman}
\newfontfamily\hebrewfont{Arial}
\begin{document}
The command is \lstinline$\newfontfamily⟨cmd⟩{font}{options}$.
\end{document}
我得到这个输出:
即使在添加注释中建议的makeatletter
-makeatlatter
代码后,括号也不会显示在输出中。
我在这里遗漏了什么?
答案1
unicode 中有两个不同的括号,而打字机字体只有一对字形 (U+2329, U+232A)(是的,即使它们看起来很相似,但根据字体的不同,它们还是有所不同)。您可以使用 literate 将未知字形映射到已知字形。
\documentclass[a4paper,11pt]{article}
\usepackage{listings}
\lstset{%
basicstyle=\ttfamily\small,
breaklines=true,
language=TeX,
extendedchars=true
}
\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
\lst@CCECUse \lst@ProcessLetter
^^^^27e8% Mathematical Left-Pointing Angle Bracket
^^^^27e9% Mathematical Right-Pointing Angle Bracket}
^^^^2329% Left-Pointing Angle Bracket
^^^^232a% Right-Pointing Angle Bracket}
^^00}
\lst@RestoreCatcodes
\lstset{literate={⟨}{〈}1{⟩}{〉}1}
\makeatother
\begin{document}
The command is \lstinline$\newfontfamily⟨cmd⟩{font}{options}$. %27e8
The command is \lstinline$\newfontfamily〈cmd〉{font}{options}$. %2329
\end{document}