¥documentclass{article}
¥usepackage{verbatim}
¥usepackage{fontspec}
¥usepackage[utf8]{inputenc}
%特殊文字用のフォント
¥setmonofont{FiraCode-Regular.ttf}[Contextuals={Alternate}]
¥usepackage{listings}
¥lstdefinelanguage{test} {
keepspaces=true,
basicstyle=¥ttfamily,
mathescape,
literate=
{↔}{$¥ensuremath{¥leftrightarrow}$}{1}
{₁}{$¥ensuremath{_1}$}{1}
}
¥begin{document}
Without listings (verbatim):
¥begin{verbatim}
∀x ∈ ℝ, (f₁ x = f₂ x) → f₁ = f₂
¥end{verbatim}
With listings:
¥begin{lstlisting}[language=test]
∀x ∈ ℝ, (f₁ x = f₂ x) → f₁ = f₂
¥end{lstlisting}
Without listings (verbatim):
¥begin{verbatim}
(P↔Q)
¥end{verbatim}
With listings:
¥begin{lstlisting}[language=test]
(P↔Q)
¥end{lstlisting}
¥end{document}
上のコードがpdf上で以下のようにコンパイルされます。添え字の₁や₂、矢印の↔が前の文字と入れ替わっています:
Without listings (verbatim):
∀x ∈ R, (f₁ x = f₂ x) → f₁ = f₂
With listings:
∀x ∈ R, (₁f x = ₂f x) → ₁f = ₂f
Without listings (verbatim):
(P↔Q)
With listings:
(↔PQ)