告诫/警告/通知中的图片

发布于 2024-08-16 13:48:19 字数 2589 浏览 6 评论 0原文

我目前使用 Sphinx 生成 LaTeX 输出,然后使用 pdftex 将其转换为 PDF 以进行书籍样式输出。

目前,我有通知、警告和其他“警告”显示在一个有界框中,其样式看起来有点像这样:

-----------------------------------
| Warning:     lorem ipsum foozle |
|  fuzzle fuzz buzz               |
|----------------------------------

生成这样一个框的 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}

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}

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

-------------------------------------------
|    ---                                  |
|   /   \                                 |
|   \   /                                 |
|    ---    Fuzzle foo buz lorem ipsum    |
-------------------------------------------

我无法更改 Sphinx 渲染的 \begin{notice} ... \end{notice} 乳胶文字(好吧,我可以,但这真的很痛苦)。我宁愿将逻辑放在新的 \newenvironment{notice} 宏中。有人可以推荐一个策略吗?到目前为止我所尝试的一切都以泪水告终。

I currently use Sphinx to generate LaTeX output which is turned into a PDF for book-style output using pdftex.

Currently, I have notices, warnings, and other "admonitions" showing up inside a bounded box, in a style that looks a little like this:

-----------------------------------
| Warning:     lorem ipsum foozle |
|  fuzzle fuzz buzz               |
|----------------------------------

The LaTeX that generates such a box looks like this:

\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}

There are a series of commands in a LaTeX .sty file that provide the box
behavior:

% 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}

Instead of just having a box around the notice and having a word represent the type of notice inside the box, I'd like to retain the box around the admonitition, but replace the word "warning" in the box with an image, like so:

-------------------------------------------
|    ---                                  |
|   /   \                                 |
|   \   /                                 |
|    ---    Fuzzle foo buz lorem ipsum    |
-------------------------------------------

I cannot change the \begin{notice} ... \end{notice} latex literals rendered by Sphinx (well, I can, but it's a real pain in the ass). I'd prefer to just put the logic in a new \newenvironment{notice} macro. Can anyone recommend a strategy? Everything I've tried so far has ended in tears.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小兔几 2024-08-23 13:48:19

尝试以下操作(这需要 \ifthenelse 命令的 ifthenxifthen 包):

% 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}
}

您必须找到一种方法来获取此内容代码放入文档的序言中。

Try the following (which requires the ifthen or xifthen package for the \ifthenelse command):

% 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}
}

You'll have to find a way to get this code into the preamble of the document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文