
最近經常使用 markdown,我想在 Latex 中以相同的方式使用反引號/反引號。因此
Using a `tt-font`
會產生相同的結果
Using a {\tt tt-font}
與兩者類似$
s 來啟用數學模式。
我知道這樣的改變是有問題的作為tex-核心使用反引號作為字元代碼,但我不會直接在我的文件中使用它們。
答案1
首先,您應該意識到\tt
(連同所有兩個字母的字體更改命令)已被棄用約 30 年。
現在你的問題了。
\documentclass{article}
\AtBeginDocument{%
\begingroup\lccode`~=``\lowercase{\endgroup\let~}\markdownbackquote
\catcode``=\active
}
\begingroup
\catcode``=\active
\protected\gdef\markdownbackquote#1`{\texttt{#1}}
\endgroup
\begin{document}
This is `typewriter` type.
\end{document}
前導碼也可能是
\begingroup
\catcode``=\active
\AtBeginDocument{%
\let`\markdownbackquote
\expandafter\catcode\string``=\active
}
\protected\gdef\markdownbackquote#1`{\texttt{#1}}
\endgroup