我有一个\comments
宏,可以插入三个居中的星号 ( * * *
) 并更改字体大小和颜色。相应的\nocomments
宏会添加另一个带有居中星号的分隔符,并恢复标准字体大小和颜色。
我希望\comments
宏对节标题敏感,也就是说,在\chapter
、\section
和\subsection
它们的朋友之后,我想暂停输出树星号和仅有的改变字体大小和颜色。
换句话说,在标题之后,宏应该直接改变字体大小和颜色,但在所有其他案例还输出‘匿名中断’(* * *
)。
我曾尝试研究诸如的核心乳胶结构\if@nobreak
,但似乎解决这个问题并不是那么简单。
\newenvironment
是的,这也可以用,但由于我使用潘多克作为前端,使用简单的宏绕过潘多克自动检测环境。无论如何,宏的解决方案可能也适用于环境。
一个不太好用的例子:
\documentclass{article}
\usepackage{xcolor}
\newcommand{\comments}{%
\begingroup
\color{blue}
% The following line should be suspended if `\begincomments' is used
% directly after a sectioning command such as `\section' or
% `\subsection'. This is just yet another of my attempts that does
% not work.
\if@noskipsec\else
\begingroup\centering * * *\par\endgroup
\fi
\small
\setlength{\parindent}{0mm}
\setlength{\parskip}{.5\baselineskip}
}
\newcommand{\nocomments}{%
\begingroup\centering * * *\par\endgroup
\endgroup
}
\begin{document}
\section{Section header}
\comments
Some comments about what will be written in this section, but is not
yet written. It should not start with three asterisks.
\nocomments
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
\comments
More comments. This should, however, start with three asterisks.
\nocomments
\end{document}
答案1
\if@nobreak
在章节标题(任何级别)之后,条件为真。您\makeatletter
可能错过了。
\documentclass{article}
\usepackage{xcolor}
\makeatletter
\newcommand{\comments}{%
\begingroup
\if@nobreak\else
\begingroup\centering \textcolor{blue}{$*\ {*}\ *$}\par\endgroup
\fi
\small
\setlength{\parindent}{0mm}
\setlength{\parskip}{.5\baselineskip}
\everypar=\expandafter{\the\everypar\color{blue}}
}
\newcommand{\nocomments}{%
\par\begingroup\centering $*\ {*}\ *$\par\endgroup
\endgroup
}
\makeatother
\begin{document}
\section{Section header}
\comments
Some comments about what will be written in this section, but is not
yet written. It should not start with three asterisks.
\nocomments
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
\comments
More comments. This should, however, start with three asterisks.
\nocomments
\end{document}
我做了一些调整以避免\color{blue}
在垂直模式下出现问题,因为这可能会产生意想不到的后果。
这是“环境”版本,comment
可以与包一起使用来静默删除注释文本。
\documentclass{article}
\usepackage{xcolor}
\makeatletter
\newenvironment{comments}{%
\if@nobreak\else
\begingroup\centering \textcolor{blue}{$*\ {*}\ *$}\par\endgroup
\fi
\small
\setlength{\parindent}{0mm}
\setlength{\parskip}{.5\baselineskip}
\everypar=\expandafter{\the\everypar\color{blue}}
}
{%
\par\begingroup\centering $*\ {*}\ *$\par\endgroup
}
\makeatother
\begin{document}
\section{Section header}
\begin{comments}
Some comments about what will be written in this section, but is not
yet written. It should not start with three asterisks.
\end{comments}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
\begin{comments}
More comments. This should, however, start with three asterisks.
\end{comments}
\end{document}