從其他路徑中的資料建立 LaTeX 模板

從其他路徑中的資料建立 LaTeX 模板

我想製作一個模板,我可以在其中修改一個 .tex 檔案並讓它從網路中提取各種「樣板檔案」(即不會更改的資訊)。首先,我會有一些 .tex,用戶將在其中複製/貼上到新資料夾中,然後指定一些內容:

%% User Data
hello world!

%% Initialize document
\input{boilerplate/Preamble} %<----This folder would be located like C://User/etc,...

然後,我將從模板資料夾中提取序言以及其餘資訊:

%% Select class
\documentclass[10pt]{article}

%% Packages
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{setspace}
\usepackage{siunitx}
\usepackage{lastpage}
\usepackage{newtxmath}
\usepackage{newtxtext}
\usepackage{textcomp}
\usepackage{longtable}
\usepackage{footnote}
\usepackage{multirow}
\usepackage{amssymb,amsmath,mathtools}
\usepackage{graphicx}
\usepackage[final]{pdfpages}
\usepackage{csvsimple}
\usepackage{grffile}
\usepackage{booktabs}
\usepackage[justification=centering]{caption}
\usepackage{longtable}
\usepackage{xcolor}
\usepackage{enumitem}
\setenumerate[1]{label=\thesection.\arabic*.}
\setenumerate[2]{label*=\arabic*.}
\usepackage[hyphens]{url}
\usepackage{breakurl} 
\usepackage[bookmarksnumbered]{hyperref}
\hypersetup{%
colorlinks=true,% hyperlinks will be coloured
citecolor=blue, % hyperlink text will be blue  
linkcolor=blue,% hyperlink text will be blue
linkbordercolor=blue,% hyperlink border will be blue
filecolor=blue,
urlcolor=blue,
breaklinks = true,
hypertexnames=true,
}
\usepackage[nameinlink]{cleveref}

%% Begin Document
\begin{document}
\input{boilerplate/Introduction} % Need path
\input{boilerplate/DetailedEquipmentInformationandRequirements} % Need path
\input{boilerplate/ProductInformation} % Need path
\input{boilerplate/SupplierScopeofWork} % Need path
\appendix
\include{boilerplate/Appendices} % Need path
\end{document}

我設想的資料夾結構是:

Template
-Boilerplate
--Introduction.tex
--DetailedEquipmentInformationandRequirements.tex
Project 1
-Compiler 1 .tex file
-Image Folder
Project 2
-Compiler 2 .tex file
-Image Folder

正如您所看到的,我需要調用序言,然後調用不在同一資料夾中的各種資料。有誰知道調用這些資訊的簡單方法或更好的管理系統?

答案1

這聽起來像是一個新的本地包或類,帶有輔助文件。

首先,建立目錄,例如mytemplate,在您的個人本機 texmf 樹中(如果您是唯一使用者),或在網站範圍的本機 texmf 樹中,或將最終範本作為 zip 檔案分發,其中包含人們如何安裝的說明它在他們的PC 上(在他們的個人電腦或站點範圍的texmf 樹中)。就我而言,在 Linux 下,我將建立mytemplate目錄

$(kpsewhich -var TEXMFHOME)/texmf/tex/latex/mytemplate

或用於網站範圍的訪問

$(kpsewhich -var TEXMFLOCAL)/tex/latex/mytemplate

無論您放入這些資料夾中的任何內容都將被找到,而無需明確路徑。請注意,網站範圍的本機目錄通常已建立索引,因此在將檔案新增至目錄後必須重建索引。在 Linux 下,我texhash以 root (admin) 身分呼叫。

公共序言和文件設定成為樣式文件mytemplate.sty,或者,如果您需要控制載入的文檔類,一個類別文件mytemplate.cls。然後,您可以使用\documentclass{mytemplate}(指mytemplate.cls) 或\documentclass{anyclass}\usepackage{mytemplate}(指)開始特定文件mytemplate.sty

可以使用儲存特定使用者資料以供以後使用的命令來收集特定使用者數據,也可以將其作為立即處理該資料的命令的參數。對於第一種方法,使用 LaTeX 的\author命令作為模型:

\newcommand\@data{} % if it is ok that no data is provided
% or alternatively
\newcommand\@data{\@latex@warning@no@line{No \noexpand\data given}} % gives a warning if the data is needed but has not provided
\newcommand\data[1]{\renewcommand\@data{#1}} % Store the argument under the name `\@data`

如果文件包含\data{42},那麼您稍後可以將樣式或類別文件中的值作為\@data.

在第二種方法中,文件呼叫巨集\processdata{42}並立即處理資料。

關於文字片段,您可以將它們作為要包含的直接 TeX 程式碼提供。該文檔有一行

\input{myintroduction}

如果myintroduction.tex位於 texmf-tree 中,則無需給出完整路徑即可找到它。或者,您的mytemplate.clsmytemplate.sty可以提供一個命令\Introduction(可能帶有一些參數)來執行一些特定的操作,並且逐字包含介紹文字或使用\input語句本身。

相關內容