警告/警告/通知中的图像

Chr*_*ugh 5 latex python-sphinx

我目前使用Sphinx生成LaTeX输出,使用pdftex将其转换为PDF,用于书籍输出.

目前,我在一个有界框内出现了通知,警告和其他"警告",其风格看起来有点像这样:

-----------------------------------
| Warning:     lorem ipsum foozle |
|  fuzzle fuzz buzz               |
|----------------------------------
Run Code Online (Sandbox Code Playgroud)

生成这样一个盒子的LaTeX看起来像这样:

\begin{notice}{warning}{Warning:}
The \code{repoze.bfg} documentation is offered under the
Creative Commons Attribution-Nonconmmercial-Share Alike 3.0 United
States License.
\end{notice}
Run Code Online (Sandbox Code Playgroud)

LaTeX .sty文件中有一系列命令可提供框行为:

% Notices / Admonitions
%
\newlength{\py@noticelength}

\newcommand{\py@heavybox}{
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{7pt}
\setlength{\py@noticelength}{\linewidth}
\addtolength{\py@noticelength}{-2\fboxsep}
\addtolength{\py@noticelength}{-2\fboxrule}
\setlength{\shadowsize}{3pt}
\Sbox
\minipage{\py@noticelength}
}
\newcommand{\py@endheavybox}{
\endminipage
\endSbox
\fbox{\TheSbox}
}

% Some are quite plain:
\newcommand{\py@noticestart@note}{}
\newcommand{\py@noticeend@note}{}
\newcommand{\py@noticestart@hint}{}
\newcommand{\py@noticeend@hint}{}
\newcommand{\py@noticestart@important}{}
\newcommand{\py@noticeend@important}{}
\newcommand{\py@noticestart@tip}{}
\newcommand{\py@noticeend@tip}{}

% Others gets more visible distinction:
\newcommand{\py@noticestart@warning}{\py@heavybox}
\newcommand{\py@noticeend@warning}{\py@endheavybox}
\newcommand{\py@noticestart@caution}{\py@heavybox}
\newcommand{\py@noticeend@caution}{\py@endheavybox}
\newcommand{\py@noticestart@attention}{\py@heavybox}
\newcommand{\py@noticeend@attention}{\py@endheavybox}
\newcommand{\py@noticestart@danger}{\py@heavybox}
\newcommand{\py@noticeend@danger}{\py@endheavybox}
\newcommand{\py@noticestart@error}{\py@heavybox}
\newcommand{\py@noticeend@error}{\py@endheavybox}

\newenvironment{notice}[2]{
  \def\py@noticetype{#1}
  \csname py@noticestart@#1\endcsname
  \par\strong{#2}
}{\csname py@noticeend@\py@noticetype\endcsname}
Run Code Online (Sandbox Code Playgroud)

我不想只是在通知周围有一个方框,并且有一个单词代表方框内的通知类型,我想保留方框周围的方框,但用图片替换方框中的"警告"一词,就像这样:

-------------------------------------------
|    ---                                  |
|   /   \                                 |
|   \   /                                 |
|    ---    Fuzzle foo buz lorem ipsum    |
-------------------------------------------
Run Code Online (Sandbox Code Playgroud)

我无法改变由Sphinx渲染的\ begin {notice} ...\end {notice}乳胶文字(嗯,我可以,但这对屁股来说真的很痛苦).我更愿意将逻辑放在一个新的\newenvironment {notice}宏中.谁能推荐一个策略?到目前为止我尝试过的所有东西都流下了眼泪.

god*_*byk 5

尝试以下(需要命令的ifthenor或xifthen\ifthenelse):

% Keep a copy of the original notice environment
\let\origbeginnotice\notice
\let\origendnotice\endnotice

% Redefine the notice environment so we can add our own code to it
\renewenvironment{notice}[2]{%
  \origbeginnotice{#1}{#2}% equivalent to original \begin{notice}{#1}{#2}
  % load graphics
  \ifthenelse{\equal{#1}{warning}}{\includegraphics{warning}}{}
  \ifthenelse{\equal{#1}{notice}}{\includegraphics{notice}}{}
  % etc.
}{%
  \origendnotice% equivalent to original \end{notice}
}
Run Code Online (Sandbox Code Playgroud)

您必须找到一种方法将此代码放入文档的前言中.