如何在布局文件中定义的环境中设置多种文本样式?

如何在布局文件中定义的环境中设置多种文本样式?

我正在尝试在布局文件中定义的环境中同时使字体等宽、粗体和小体。这似乎是一件非常简单的事情,但我已经为此苦苦挣扎了几个小时。

以下是不起作用的内容:

\newenvironment{ogc_chapter_date}{
   \raggedright
   \begin{texttt}
   \begin{small}
   \begin{bffamily}
}{
   \end{bffamily}
   \end{small}
   \end{texttt}
   \par
}

以上内容在我的 Lyx.layout文件中。

编译失败时我在日志中看到的内容:

! Missing \endcsname inserted.
<to be read again> 
                   \aftergroup 
l.137 \begin{ogc_chapter_date}

The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

! Extra \endcsname.
\@ifundefined ...dafter \ifx \csname #1\endcsname 
                                                  \relax \expandafter \@firs...
l.137 \begin{ogc_chapter_date}

I'm ignoring this, since I wasn't doing a \csname.

! Extra \else.
\@ifundefined ... \expandafter \@firstoftwo \else 
                                                  \expandafter \@secondoftwo...
l.137 \begin{ogc_chapter_date}

I'm ignoring this; it doesn't match any \if.

! Undefined control sequence.
\reserved@a ->\@nil 

l.137 \begin{ogc_chapter_date}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Extra }, or forgotten \endgroup.
<recently read> \egroup 

l.137 \begin{ogc_chapter_date}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.


! LaTeX Error: \begin{texttt} on input line 137 ended by \end{bffamily}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.139 \end{ogc_chapter_date}

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

! Missing } inserted.
<inserted text> 
                }
l.139 \end{ogc_chapter_date}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

答案1

您使用\texttt需要参数的宏作为环境名称。这会导致第一个错误。请ttfamily改用。下一个是bffamily未定义。正确的名称是bfseries。您可以在LaTeX 字体指南

还要注意,用作环境的命令应该用作开关,例如 而\ttfamily不是\begin{ttfamily},尽管 LaTeX 的环境实现仍然允许这种用法。

因此我建议使用以下定义(也许还应该避免在环境名称中使用下划线)。

\newenvironment{ogc_chapter_date}{
   \raggedright
   \ttfamily
   \small
   \bfseries
}{
   \par
}

请注意,环境内部使用\begingroup并且\endgroup这里限制字体命令的效果范围。

相关内容