孙子 \input{styles} 中的独立包的范围问题

孙子 \input{styles} 中的独立包的范围问题

[Win7 上的 MiKTeX]

我将文档根据章节细分为不同的文件,并且使用HighlightUbuntu 上的包生成了一系列 TeX 格式的代码片段,需要将其插入到各个章节中。

我遇到的问题是:

  • 使用standalone没有subpreambles标志的包,定义的符号highlight.sty不起作用(因为\input命令在其前言中。)

  • 使用standalone带有subpreambles标志的包我收到以下错误:

    ! Undefined control sequence.
    <argument> \datapath 
                         /highlight.sty
    l.3 ...ge {alltt}\input {\datapath /highlight.sty}
                                                      \title {wb_ardrone_perform...
    
  • 当我使用注释掉包import的包时standalone,出现以下错误:

    Figures/wb_ardrone_performance.tex
    
    ! LaTeX Error: Can be used only in preamble.
    
    See the LaTeX manual or LaTeX Companion for explanation.
    Type  H <return>  for immediate help.
     ...                                              
    
    l.2 \documentclass
                      {article}
    

以下是我的文档结构的描述,后面是每个组件的代码(已删减以保证相关性)。我的文档布局如下:

高级结构(主要)带有章节(子级)
子级需要导入代码片段(孙级)
孙级需要阅读highlight.sty。

代码:
主要(结构):

\documentclass[a4paper,twoside]{article}
\usepackage{standalone}
%\usepackage[subpreambles]{standalone}
%\usepackage{import}
\usepackage{xstring}

\newcommand{\includestandalonewithpath}[2][]{%
  \begingroup%
  \StrCount{#2}{/}[\matches]%
  \ignorespaces 
  \StrBefore[\matches]{#2}{/}[\datapath]%
  \includestandalone[#1]{#2}%
  \endgroup%
}

\begin{document}
  \section{\uppercase{Child 1}}
  \noindent\input{child1}
  %%%   and so on for subsequent chapters  %%%
\end{document}

儿童(章节):

% child1
% NO \begin{document} here (Not needed)

\begin{figure}
  \begin{center}
    %%%  THESE are the various commands I've tried.  %%%
    %\input {Figures/wb_ardrone_performance}
    \includestandalone{Figures/wb_ardrone_performance}
    %\includestandalone{C:/Tmp/Figures/wb_ardrone_performance}
    %\includestandalonewithpath {Figures/wb_ardrone_performance}
    %\includestandalonewithpath [mode=tex]{Figures/wb_ardrone_performance}
    %\subimport*{Figures/}{wb_ardrone_performance.tex}
    %\fbox{\includegraphics[width=.40\textwidth]{Figures/wb_ardrone_performance.pdf}}
    %\fbox{\input wb_ardrone_performance.tex}
  \end{center}
  \caption{\label{fig:temp} a simple message in C}
\end{figure}

% NO \end{document} here (Not needed)

孙子(wb_ardrone_performance):

\providecommand{\dataPath}{.}
\documentclass[varwidth]{standalone}

\usepackage{color}
\usepackage[latin1]{inputenc}
\usepackage{alltt}


%\input{highlight.sty}
\input{\dataPath/highlight.sty}

\begin{document}
  \pagecolor{bgcolor}  <===== doesn't know what bgcolor is!
  \hlstd{}\hlppc{\#ifndef\ \textunderscore WBARDRONEPERFORMANCE\textunderscore }\hspace*{\fill}\\  <===== doesn't know what any of the tokens are!
\end {document}

highlight.sty(由 UbuntuHighlight包生成):

% Style definition file generated by highlight 3.16.1, http://www.andre-simon.de/ 
% Highlighting theme: Kwrite Editor 
\newcommand{\hlstd}[1]{\textcolor[rgb]{0,0,0}{#1}}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.69,0.49,0}{#1}}
\newcommand{\hlesc}[1]{\textcolor[rgb]{1,0,1}{#1}}
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.75,0.01,0.01}{#1}}
\newcommand{\hlpps}[1]{\textcolor[rgb]{0.51,0.51,0}{#1}}
\newcommand{\hlslc}[1]{\textcolor[rgb]{0.51,0.51,0.51}{\it{#1}}}
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.51,0.51,0.51}{\it{#1}}}
\newcommand{\hlppc}[1]{\textcolor[rgb]{0,0.51,0}{#1}}
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}
\newcommand{\hlipl}[1]{\textcolor[rgb]{0,0.34,0.68}{#1}}
\newcommand{\hllin}[1]{\textcolor[rgb]{0.33,0.33,0.33}{#1}}
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0,0,0}{\bf{#1}}}
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0,0.34,0.68}{#1}}
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0,0,0}{\bf{#1}}}
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0,0,0.51}{#1}}
\definecolor{bgcolor}{rgb}{1.0,1.0,1.0}
\pagestyle{empty}

希望我提供的信息都是正确的。
如果能帮我找出它为什么不起作用,我将不胜感激。

干杯,Nap

已移除 \test来自 Grand-Child 文档。在诊断打印问题时使用它。

答案1

xstring处理standalone使得这个变得比它需要的更加复杂和脆弱,我只会使用\input

在下面我将其改为highlight.sty灰色bgcolor而不是白色,以便它显示出来,如果你想要白色,请将其放回去或简单地删除\colorbox{bgcolor}

在此处输入图片描述


主文本

\documentclass[a4paper,twoside]{article}

\usepackage{varwidth,color,highlight}

\begin{document}
\section{Child 1}

% no!!  \noindent

\input{child1}
  %%%   and so on for subsequent chapters  %%%
\end{document}

child1.tex

\begin{figure}[htp]
  %\begin{center} use \centering not center in figures.
  \centering
    \input{Figures/wb_ardrone_performance}
  \caption{\label{fig:temp} a simple message in C}
\end{figure}

图片/wb_ardrone_performance.tex

  \colorbox{bgcolor}{\begin{varwidth}{\textwidth}
  \hlstd{}\hlppc{\#ifndef\ \textunderscore WBARDRONEPERFORMANCE\textunderscore }\hspace*{\fill}
  % not defined?\test
\end{varwidth}}

亮点.sty

% Style definition file generated by highlight 3.16.1, http://www.andre-simon.de/ 
% Highlighting theme: Kwrite Editor 
\newcommand{\hlstd}[1]{\textcolor[rgb]{0,0,0}{#1}}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.69,0.49,0}{#1}}
\newcommand{\hlesc}[1]{\textcolor[rgb]{1,0,1}{#1}}
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.75,0.01,0.01}{#1}}
\newcommand{\hlpps}[1]{\textcolor[rgb]{0.51,0.51,0}{#1}}
\newcommand{\hlslc}[1]{\textcolor[rgb]{0.51,0.51,0.51}{\it{#1}}}
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.51,0.51,0.51}{\it{#1}}}
\newcommand{\hlppc}[1]{\textcolor[rgb]{0,0.51,0}{#1}}
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}
\newcommand{\hlipl}[1]{\textcolor[rgb]{0,0.34,0.68}{#1}}
\newcommand{\hllin}[1]{\textcolor[rgb]{0.33,0.33,0.33}{#1}}
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0,0,0}{\bf{#1}}}
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0,0.34,0.68}{#1}}
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0,0,0}{\bf{#1}}}
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0,0,0.51}{#1}}
\definecolor{bgcolor}{rgb}{.8,.8,.8}
\pagestyle{empty}

相关内容