括號子句的機制類似 csquotes 的 MakeAutoQuote

括號子句的機制類似 csquotes 的 MakeAutoQuote

我有以下巨集用於編寫括號子句:

\makeatletter
\newcommand\incise[1]{%
    ---\,#1%
    \@ifnextchar.\relax{\@ifnextchar?{\@ifnextchar!{\@ifnextchar:{\@ifnextchar;\relax{\,---}}}}}
}
\makeatother

但我想做與 csquote 套件相同的引用操作。它使用活動字元而不是乳膠宏。

那麼,LaTeX 中是否有可能:

The main sentence -(the parenthetical clause)-.

轉變為:

The main sentence \incise{the parenthetical clause}.

答案1

\catcode`*\active
\def*(#1)*{\incise{#1}}

*(xxxx)*只要你不在*其他地方使用,就可以按照你喜歡的方式行事......

答案2

您可以使用 csquotes 命令 - 它們甚至可以使用 utf8 字符,而您不能直接使用\catcodeDavid 的技巧。主要問題是選擇字符,以免對文件的其餘部分產生副作用。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csquotes,xcolor}

\makeatletter
\csq@addspecial{ä}{\begingroup---!ups\color{red}}{}{}%
\csq@addspecial{ö}{\endgroup!ups---}{}{}
\makeatother

 \begin{document}
 äblubö blabla 

 \end{document} 

相關內容