![问题:](https://linux22.com/image/418722/%E9%97%AE%E9%A2%98%EF%BC%9A.png)
我正在使用 KOMA-scripts\makenote*{}
命令在页边空白处做笔记。示例:
%! TEX program = lualatex
\documentclass[oneside, titlepage = false, fontsize = 12pt]{scrbook}
\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}
\usepackage{fontspec,geometry}
\setmainfont{cmun}[
Extension=.otf,
UprightFont=*rm,
ItalicFont=*ti,
BoldFont=*bx,
BoldItalicFont=*bi,
]
\usepackage[most]{tcolorbox}
\newtcbtheorem[]{memoanmich}{Memo an mich selbst}{colback=black!15,colframe=black!80,fonttitle=\bfseries,left=0mm,right=0mm}{memoanmich}
\begin{document}
\newgeometry{left=1.8cm, right=5.6cm, top = 2cm, bottom = 3cm, marginpar=5cm, footskip = 1cm}
\makenote*{\begin{small}\begin{memoanmich*}{}{}
Some maths: $\sum_{n=1}^{\infty}1/n^2$
\end{memoanmich*}\end{small}}
test
\end{document}
本例相关代码:
\makenote*{\begin{small}\begin{memoanmich*}{}{}
Some maths: $\sum_{n=1}^{\infty}1/n^2$
\end{memoanmich*}\end{small}}
为了使内容更具可读性,我决定引入一个新环境:
\newenvironment{mams}
{\begin{small}\begin{memoanmich*}{}{}}
{\end{memoanmich*}\end{small}}
现在我的笔记命令如下所示:
\makenote*{\begin{mams}
Some maths: $\sum_{n=1}^{\infty}1/n^2$
\end{mams}}
问题:
是否可以将\makenote*{}
命令添加到我的环境中mams
,以便我的注释命令如下所示:
\begin{mams}
Some maths: $\sum_{n=1}^{\infty}1/n^2$
\end{mams}
或者像这样:
\begin{mams}{Some maths: $\sum_{n=1}^{\infty}1/n^2$}
\end{mams}
我的尝试
包裹环境
相反\newenvironment
,我尝试了以下代码:
\usepackage{environ}
\NewEnviron{mams}{%
\makenote*{\begin{small}\begin{memoanmich*}{}{}%
\BODY
\end{memoanmich*}\end{small}}}
我收到的错误:
Undefined control sequence. \begin {small}\begin{memoanmich*}{}{}\BODY
\begingroup
和\endgroup
\newenvironment{mams}{\makenote*\begingroup\begin{small}\begin{memoanmich*}{}{}}
{\end{memoanmich*}\end{small}\endgroup}
我收到的错误:
LaTeX Error: \begin{document} ended by \end{mams}. Extra \endgroup.
\newsavebox
\newsavebox{\mymemobox}
\newenvironment{mams}[1]{\sbox\mymemobox{#1}}{\makenote*{\begin{small}\begin{memoanmich*}{}{}\usebox{\mymemobox}\end{memoanmich*}\end{small}}}
相关的注释命令现在如下所示:
\begin{mams}{Some maths: $\sum_{n=1}^{\infty}1/n^2$}\end{mams}
编译时没有任何错误,但我没有得到注释本身,即tcolorbox
绘制彩色框,字体很小(这意味着环境\begin{small}
处于活动状态),彩色框在边缘(这意味着命令\makenote*{}
有效)。唯一缺少的是注释本身,即
Some maths: $\sum_{n=1}^{\infty}1/n^2$
完整代码:
%! TEX program = lualatex
\documentclass[oneside, titlepage = false, fontsize = 12pt]{scrbook}
\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}
\usepackage{fontspec,geometry}
\setmainfont{cmun}[
Extension=.otf,
UprightFont=*rm,
ItalicFont=*ti,
BoldFont=*bx,
BoldItalicFont=*bi,
]
\usepackage[most]{tcolorbox}
\newtcbtheorem[]{memoanmich}{Memo an mich selbst}{colback=black!15,colframe=black!80,fonttitle=\bfseries,left=0mm,right=0mm}{memoanmich}
\newsavebox{\mymemobox}
\newenvironment{mams}[1]{\sbox\mymemobox{#1}}{\makenote*{\begin{small}\begin{memoanmich*}{}{}\usebox{\mymemobox}\end{memoanmich*}\end{small}}}
\begin{document}
\newgeometry{left=1.8cm, right=5.6cm, top = 2cm, bottom = 3cm, marginpar=5cm, footskip = 1cm}
\begin{mams}{Some maths: $ \sum_{n=1}^{\infty}1/n^2$}\end{mams}
test
\end{document}
答案1
您可以使用 xparse 和 b 参数类型:
\documentclass[oneside, titlepage = false, fontsize = 12pt]{scrbook}
\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}
\usepackage{fontspec,geometry}
\setmainfont{cmun}[
Extension=.otf,
UprightFont=*rm,
ItalicFont=*ti,
BoldFont=*bx,
BoldItalicFont=*bi,
]
\usepackage[most]{tcolorbox}
\newtcbtheorem[]{memoanmich}{Memo an mich selbst}{colback=black!15,colframe=black!80,fonttitle=\bfseries,left=0mm,right=0mm}{memoanmich}
\usepackage{xparse} %no longer needed in next latex version
\NewDocumentEnvironment{mams}{b}
{%
\makenote*{%
\small
\begin{memoanmich*}{}{}
#1
\end{memoanmich*}}%
}{}
\begin{document}
\newgeometry{left=1.8cm, right=5.6cm, top = 2cm, bottom = 3cm, marginpar=5cm, footskip = 1cm}
\begin{mams}
Some maths: $\sum_{n=1}^{\infty}1/n^2$
\end{mams}
test
\end{document}