全局命令,这样一些浮动环境就根本不显示

全局命令,这样一些浮动环境就根本不显示

我正在使用包newfloat来定义附加图形环境(用于补充图形)。期刊要求我在单独的文档中提供这些内容。

理想情况下,我只需要在标题中将变量设置为 0 或 1,然后编译pdflatex即可生成一个 pdf 文件,要么完全没有补充图,要么在文件末尾有补充图。我当然希望保持对labels补充图的引用有效 - 我也希望保持超级引用有效(当然补充图除外),所以我相信这意味着避免拆分 pdf后验(但我会接受保留超链接但涉及使用 Linux 命令进行 PDF 拆分步骤的解决方案)。

梅威瑟:

\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
    fileext=los,
    listname={List of Supplementary Figures},
    name={Supplementary Figure},
    placement=tbhp,
]{suppfigure}
\usepackage[nomarkers,tablesonly,notablist]{endfloat}
\DeclareDelayedFloatFlavor*{suppfigure}{table}
\begin{document}
There's the main figure \ref{fig.main} and 
the supplemetary one \ref{fig.supp}. 
The main one should be at the bottom of this page, 
the supplementary one in a separate pdf file.
\begin{figure}[b]
\centering\Huge{A}
\caption{Main fig}
\label{fig.main}
\end{figure}
\begin{suppfigure}[b] 
\centering\Huge{B}
\caption{Supp fig}
\label{fig.supp}
\end{suppfigure}
\lipsum[1-7]
\end{document}

(请注意,就我而言,我将 Supp Figures 声明为“表格” endfloat,因为看起来包不会接受在文本中保留图形并在末尾放置自定义浮动图形环境的选项。)

编辑:我曾尝试endfloat将延迟图形嵌入“黑洞”环境,但在编译时出现错误。我在 latex 文件序言中插入了以下内容:

%% Black hole for supplementary figures
\newif\ifshowsupp
\showsupptrue
\usepackage{environ}
\NewEnviron{hidefloat}{
  \ifshowsupp
    \BODY
  \fi}
\renewcommand{\efloatpreamble}{\begin{hidefloat}}
\renewcommand{\efloatseparator}{\end{hidefloat}\begin{hidefloat}}
\renewcommand{\efloatpostamble}{\end{hidefloat}}

错误是“ ! Argument of \hidefloat has an extra }.”,据说是在到达 时引发的\end{document},尽管我已检查\efloat...命令是否按 要求调用endfloat。我尝试使用solution包中的环境exsheet并得到了相同的结果。

答案1

我的方法是将所有suppfigure环境自动捕获到一个新文件中,例如suppfigs.tex。此文件将在编译过程中逐步构建,其中包含suppfigure您可能使用的任何内容。然后\AtEndDocument,您可以suppfigs.tex按原样导入,并在文档末尾设置所有补充图。这样可以保留所有\ref引用和超链接。

在此处输入图片描述

\documentclass{article}

\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
    fileext=los,
    listname={List of Supplementary Figures},
    name={Supplementary Figure},
    placement=tbhp,
]{suppfigure}

\usepackage{newfile}

\newoutputstream{suppfigs}
\AtBeginDocument{%
  \openoutputfile{suppfigs.tex}{suppfigs}% Create file that will store supplemental figures
  \addtostream{suppfigs}{
    % Restore way supplemental figures are handled (originally redefined to only store its contents)
    \protect\let\protect\suppfigure\protect\oldsuppfigure
    \protect\let\protect\endsuppfigure\protect\endoldsuppfigure
  }
}
\AtEndDocument{%
  \closeoutputstream{suppfigs}% Close stream that should contain any supplemental figures
  \input{suppfigs}% Input gathered supplemental figures
}

\usepackage{environ}
% Despite creating supplemental figure floating environment, redefine it to just capture its contents.
% First store the original definitions (of \begin{suppfigure} and \end{suppfigure})
\let\oldsuppfigure\suppfigure
\let\endoldsuppfigure\endsuppfigure
% Redefine suppfigure to write its content to the suppfigs output stream
\RenewEnviron{suppfigure}[1][tbhp]{%
  % Within the environment we temporarily change the definition of fragile elements to \relax.
  % This ensures they won't be expanded when written to the suppfigs.tex output file.
  \let\label\relax
  \let\caption\relax
  % List other commands here that you may use that need protection from expansion (remember, this is only temporary)
  \addtostream{suppfigs}{% Write entire environment to output file
    \begin{suppfigure}[#1]
      \BODY
    \end{suppfigure}
  }%
}

\begin{document}

There's the main Figure~\ref{fig.main} and 
the supplementary one as Figure~\ref{fig.supp}. 
The main one should be at the bottom of this page, 
the supplementary one in a separate PDF file.

\begin{figure}[b]
  \centering\Huge{A}
  \caption{Main fig}
  \label{fig.main}
\end{figure}

\begin{suppfigure}[b] 
  \centering\Huge{B}
  \caption{Supp fig}
  \label{fig.supp}
\end{suppfigure}

\lipsum[1-20]

\end{document}

相关内容