バックティックを \tt モードとして使用する方法

バックティックを \tt モードとして使用する方法

最近はマークダウンをよく使っているので、Latexでも同じようにバックティック/バッククォートを使いたいと考えています。

Using a `tt-font`

同じ結果になる

Using a {\tt tt-font}

2つの$sを有効にするのと同様に

私は承知していますこのような変化は問題であるとして文字コードにはバックティックを使用しますが、ファイル内では直接使用しません。

答え1

まず、\tt(すべての 2 文字のフォント変更コマンドとともに) は約 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

関連情報