如何用 «» 定義新的數學分隔符號?

如何用 «» 定義新的數學分隔符號?

我想使用帶有符號 «»(法國海鳩)的特殊數學括號。但問題是,當我使用\mbox或定義它們時\text,它們會與周圍的文字一起變成斜體。

\documentclass[12pt,a4paper]{letter}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
\newcommand{\fopen}{\mathopen\text{\guillemotleft}}
\newcommand{\fclose}{\mathclose\text{\guillemotright}}
\newcommand{\ff}[1]{\fopen #1\fclose}   

\textbf{What I have}

With normal text $\ff{O:P:Q}$ 

{\itshape With text in italic $\ff{O:P:Q}$ } (guillemots in italic)

\textbf{What it should be}

With normal text $\ff{O:P:Q}$ 

{\itshape With text in italic}  $\ff{O:P:Q}$ 
\end{document}

math_guillemots_斜體

答案1

使用的字體\text是數學公式開始時有效的字體,因此在斜體上下文中它將是斜體。

使用\textnormal, 代替:

\newcommand{\fopen}{\mathopen{\textnormal{\guillemotleft}}}
\newcommand{\fclose}{\mathclose{\textnormal{\guillemotright}}}

另請注意附加的大括號;只是因為實施的緣故,您不會收到錯誤訊息。在下面的範例中,我還添加了一種使命令尊重的方法\boldmath

\documentclass[12pt,a4paper]{letter}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{pdftexcmds}

\makeatletter
\newcommand{\normalorbold}{%
  \ifnum\pdf@strcmp{\math@version}{bold}=\z@\bfseries\fi
}
\makeatother

\newcommand{\fopen}{\mathopen{\textnormal{\normalorbold\guillemotleft}}}
\newcommand{\fclose}{\mathclose{\textnormal{\normalorbold\guillemotright}}}
\newcommand{\ff}[1]{\fopen #1\fclose}   

\begin{document}

\textbf{What I have}

With normal text $\ff{O:P:Q}$ 

{\itshape With text in italic $\ff{O:P:Q}$}

\textbf{What it should be}

With normal text $\ff{O:P:Q}$ 

{\itshape With text in italic}  $\ff{O:P:Q}$ 

{\boldmath $\ff{O:P:Q}$}

\end{document}

在此輸入影像描述

如果您不缺少符號字體,您可以定義一種:

\documentclass[12pt,a4paper]{letter}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\DeclareSymbolFont{supplsymbols}{T1}{\familydefault}{m}{n}
\SetSymbolFont{supplsymbols}{bold}{T1}{\familydefault}{bx}{n}

\DeclareMathSymbol{\fopen}{\mathopen}{supplsymbols}{19}
\DeclareMathSymbol{\fclose}{\mathclose}{supplsymbols}{20}
\newcommand{\ff}[1]{\fopen #1\fclose}   

\begin{document}

\textbf{What I have}

With normal text $\ff{O:P:Q}$ 

{\itshape With text in italic $\ff{O:P:Q}$}

\textbf{What it should be}

With normal text $\ff{O:P:Q}$ 

{\itshape With text in italic}  $\ff{O:P:Q}$ 

{\boldmath $\ff{O:P:Q}$}

\end{document}

相關內容