
답변1
자동으로 크기가 조정되는 두 가지 대안 N
:
\documentclass{article}
\usepackage{amstext}% or package amsmath for \text
\newcommand*{\ttmath}[1]{%
\texttt{\mdseries\upshape#1}%
}
\begin{document}
$2^{\verb|N|-1}$ {\small(\verb|\verb|)}
$2^{\texttt{N}-1}$ {\small(\verb|\texttt| with \verb|amstext|)}
\textit{Italics $2^{\ttmath{N}-1}$ context} {\small(macro \verb|\ttmath|)}
$2^{\mathtt{N}-1}$ {\small(\verb|\mathtt|)}
\end{document}
비고:
\texttt
여기서는 내부적으로\nfss@text
패키지amstext
에서\text
.매크로는
\ttmath
또한 현재 텍스트 글꼴 설정에서 독립되도록 글꼴 속성 시리즈 및 모양을 재설정합니다.\mathtt
가장 효율적인 명령이며 수학용으로 구성된 타자기 글꼴을 사용합니다. 이것은 종종 와 동일합니다\ttfamily
. 일부 글꼴 패키지는 와 동시에 두 글꼴을 모두 전환하지만lmodern
다른 글꼴 패키지는 와 같이 전환하지 않습니다beramono
. 따라서 또는\mathtt
대신 사용할 수 있는지 여부는 글꼴 설정에 따라 다릅니다 .\verb
\texttt
답변2
LaTeX 커널은 정의 \mathtt
하며 다른 것은 필요하지 않습니다. 그건 그렇고, \verb
타자기 글꼴로 인쇄하는 데 남용해서는 안 되며 일반적 \texttt
으로 충분하지만 \verb
특수 문자가 있는 TeX 코드를 인쇄하는 데 필요합니다.
\documentclass{article}
\begin{document}
$2^{\mathtt{N}-1}$
$2^{\mathtt{N}^{\mathtt{M}}}$
\end{document}
아마도 자신만의 의미 명령을 정의하는 것이 유용할 것입니다.
\newcommand{\tvar}[1]{\mathtt{#1}}
을 사용하고 $2^{\tvar{N}}$
. 이렇게 하면 정의를 수정하여 언제든지 변경할 수 있는 특정 표현에 얽매이지 않습니다.
다른 글꼴 세트를 선택해도 업데이트되지 않을 수 있습니다 \mathtt
. 솔루션은 간단하며 다른 솔루션에 비해 장점은 즉시 \text
지원하도록 쉽게 조정할 수 있다는 것입니다 .\boldmath
\documentclass{article}
\usepackage[T1]{fontenc} % necessary for beramono
\usepackage{amsmath}
\usepackage{beramono}
% update \mathtt to use the same font as \ttfamily
\DeclareMathAlphabet{\mathtt}{\encodingdefault}{\ttdefault}{m}{n}
% if the monospaced font also supports boldface (b or bx)
\SetMathAlphabet{\mathtt}{\encodingdefault}{\ttdefault}{b}{n}
\newtheorem{theorem}{Theorem}
\begin{document}
$2^{\mathtt{N}-1}$ and \texttt{N}
\begin{theorem}
Something about $2^{\mathtt{N}-1}$
\end{theorem}
\end{document}
참고 사항
\texttt
다음 코드와 같이 사용이 잘못되었습니다.
\documentclass{article}
\usepackage{amsmath}
\newcommand{\tvar}[1]{\mathtt{#1}}
\newtheorem{theorem}{Theorem}
\begin{document}
\section*{Right}
$2^{\tvar{N}-1}$
\begin{theorem}
Something about $2^{\tvar{N}-1}$
\end{theorem}
\section*{Wrong}
$2^{\texttt{N}-1}$
\begin{theorem}
Something about $2^{\texttt{N}-1}$
\end{theorem}
\end{document}
답변3
Werner의 답변을 사용한 솔루션은 다음과 같습니다.https://tex.stackexchange.com/a/120694/120578
\documentclass{article}
\usepackage{verbatim}% http://ctan.org/pkg/verbatimes
\usepackage{pgf}
\makeatletter
\newcommand{\mverbatimfont}{\def\verbatim@font{\ttfamily}}%
\makeatother
\def\verbatimfont#1{\pgfmathsetmacro\bls{1.2*#1}\mverbatimfont\fontsize{#1}{\bls}\selectfont}
\begin{document}
\verbatimfont{6}
$2^{\verb|N|-1}$
\verbatimfont{9}
$\verb|N|^{\verbatimfont{6}\verb|N|-1}$
\end{document}
산출: