使用 Writer2LaTeX 生成的文档作为起点来开发文档类

使用 Writer2LaTeX 生成的文档作为起点来开发文档类

背景

我的大学终于开始更加了解 LaTeX,并开发和发布了针对论文和回忆录的文档类。该类基于该类memoir,现在作为 TeX Live 2012 的一部分发布。

在我的部门,至少有一位教授精通使用 LaTeX。我已经开始与这位教授合作,以便让部门其他成员,尤其是雇用我的研究中心的成员了解 LaTeX。

最近,在编辑一篇论文时,我发现我所在研究中心的许多作者在根据提供的指南格式化他们的工作时都不知所措。在说服部门提供样式表和精确的说明将使参与创作和编辑的每个人都受益之后,我被赋予了开发 OpenOffice/LibreOffice 和 Microsoft Word 模板的工作。我已经完成了这项任务,现在我想创建一个相应的 LaTeX 文档类,以促进使用 LaTeX 作为当前文字处理器 > InDesign > PDF 工作流程的替代方案。

主要问题

我有一个 OpenDocument Text 模板,其中包含作者在编辑过程中可能需要的所有样式。由于文本正文段落、块引用样式等方面存在很大差异,因此从 ODT 模板生成 LaTeX 类似乎是最实用的解决方案,因为 LaTeX 模板需要包含与 ODT 模板相同的所有样式并与之保持一致。

我已经使用 Writer2LaTeX 排版我为研究中心制作的所有文档。Writer2LaTeX 1.2 版(目前为测试版)在给定文档的格式已使用样式正确定义(而不是手动格式化)时生成合适的前言。我绝对要求(我认为在当今时代是合理的)使用 XeTeX 或 LuaTeX,因为我从事的领域(早期现代文学)需要真正的 Unicode 支持,并且大多数文档必然包含多种语言(通常是法语、英语和拉丁语,偶尔还有多音阶希腊语和基于西里尔语的语言)。这就是为什么我使用 Writer2LaTeX 1.2 并将引擎设置为“XeTeX”。通常,我需要做的就是fontspec向前言添加命令,然后我就可以排版文档,而无需对生成的 LaTeX 进行任何进一步干预。

但是,对于基于 LaTeX 的工作流程,复制 Writer2LaTeX 前言是不行的。我需要开发一个真正的类。我的直觉是,我可以使用 Writer2LaTeX 作为起点,并为我的类保留相同的命令名称。这些命令通常以\textStyle和其他类似的前缀开头,具体取决于生成它们的 ODT 样式系列。这样,该类将保留接近 OpenDocument 样式模型的概念和区别。我需要知道的是:我可以将包含我需要的所有样式命令的前言转储到类文件中吗?我对类开发了解不多,但有东西告诉我这不是最佳做法。最好的路线是什么?通过“打开引擎盖”并编写额外的 XSLT 来定制 Writer2LaTeX 的输出?我承认,首先我还没有学过 XSLT。

子问题

如何使 Writer2LaTeX 生成的前言更具可读性?一般来说,我知道可以通过%在各个语句末尾放置注释字符将 LaTeX 命令拆分为多行,但在某些特殊情况下这种方法是否有注意事项?我的目标是使类代码尽可能具有可读性:我希望它看起来有点像 CSS,在我看来,CSS 是目前最好看的语言之一,并且编写起来很有魅力。

总结一下:我是否应该使 Writer2LaTeX 的输出更具可读性并通过添加fontspec定义等对其进行微调,还是应该从 Writer2LaTeX 的输出中获得灵感并使用标准类开发工具从头开始编写我的类?

编辑:这是一个由创建的序言的示例Writer2LaTeX。这是从我的一份课程作业文档生成的。我自己添加的唯一命令是\setmainfont{Brill}

% This file was converted to LaTeX by Writer2LaTeX ver. 1.2
% see http://writer2latex.sourceforge.net for more info
\documentclass[letterpaper,12pt]{article}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{fontspec}
\setmainfont{Brill}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage{french}
\setotherlanguage{english}
\usepackage{color}
\usepackage{fancyhdr}
\usepackage[top=3.39cm,bottom=3.39cm,left=3.39cm,right=3.39cm,nohead,includefoot,foot=1.016cm,footskip=1.524cm]{geometry}
\usepackage{array}
\usepackage{hhline}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue, citecolor=blue, filecolor=blue, urlcolor=blue}
% footnotes configuration
\makeatletter
\renewcommand\thefootnote{\arabic{footnote}}
\renewcommand\@makefnmark{\mbox{\textstyleFootnoteanchor{\@thefnmark}}}
\makeatother
% Text styles
\newcommand\textstyleEmphasis[1]{\textfrench{\textrm{\textit{#1}}}}
\newcommand\textstyleSuperscript[1]{\textsuperscript{#1}}
\newcommand\textstyleNumberingSymbols[1]{#1}
\newcommand\textstyleStephanusnum[1]{\textrm{\textsuperscript{#1}}}
\newcommand\textstyleFootnoteanchor[1]{\textrm{\textsuperscript{#1}}}
% Headings and outline numbering
\makeatletter
\newcommand\cssection[1]{\textfrench{#1}}
\renewcommand\section{\@startsection{section}{1}{0.0cm}{0.559cm}{0.559cm}{\normalfont\normalsize\normalcolor\fontsize{16pt}{19.2pt}\selectfont\rmfamily\mdseries\cssection}}
\newcommand\cssubsection[1]{\textfrench{#1}}
\renewcommand\subsection{\@startsection{subsection}{2}{0.0cm}{0.28cm}{0.28cm}{\normalfont\normalsize\normalcolor\fontsize{12pt}{14.4pt}\selectfont\rmfamily\mdseries\itshape\cssubsection}}
\renewcommand\@seccntformat[1]{\csname @textstyle#1\endcsname{\csname the#1\endcsname}\csname @distance#1\endcsname}
\setcounter{secnumdepth}{0}
\newcommand\@distancesection{}
\newcommand\@textstylesection[1]{#1}
\newcommand\@distancesubsection{}
\newcommand\@textstylesubsection[1]{#1}
\makeatother
\raggedbottom
% Paragraph styles
\renewcommand\familydefault{\rmdefault}
\newenvironment{stylePii}{\clearpage\setcounter{page}{1}\pagestyle{Standard}
\thispagestyle{FirstPage}
\setlength\leftskip{0cm plus 1fil}\setlength\rightskip{0cm plus 1fil}\setlength\parindent{0cm}\setlength\parfillskip{0pt}\setlength\parskip{0cm plus 1pt}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\fontsize{24pt}{28.8pt}\selectfont\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0.559cm plus 0.0559cm}\par}
\newenvironment{styleAuthor}{\renewcommand\baselinestretch{1.25}\setlength\leftskip{0cm plus 1fil}\setlength\rightskip{0cm plus 1fil}\setlength\parindent{0cm}\setlength\parfillskip{0pt}\setlength\parskip{0cm plus 1pt}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\upshape\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0cm plus 1pt}\par}
\newenvironment{styleDate}{\renewcommand\baselinestretch{1.25}\setlength\leftskip{0cm plus 1fil}\setlength\rightskip{0cm plus 1fil}\setlength\parindent{0cm}\setlength\parfillskip{0pt}\setlength\parskip{0cm plus 1pt}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\upshape\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0cm plus 1pt}\par}
\newenvironment{styleTextbody}{\renewcommand\baselinestretch{1.0}\setlength\leftskip{0cm}\setlength\rightskip{0cm}\setlength\parindent{0.559cm}\setlength\parfillskip{0pt plus 1fil}\setlength\parskip{0cm plus 1pt}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0cm plus 1pt}\par}
\newenvironment{styleQuotations}{\setlength\leftskip{1.131cm}\setlength\rightskip{1.131cm}\setlength\parindent{0cm}\setlength\parfillskip{0pt plus 1fil}\setlength\parskip{0.559cm plus 0.0559cm}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0.559cm plus 0.0559cm}\par}
\newenvironment{stylePv}{\setlength\leftskip{0cm}\setlength\rightskip{0cm}\setlength\parindent{0cm}\setlength\parfillskip{0pt plus 1fil}\setlength\parskip{0cm plus 1pt}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0cm plus 1pt}\par}
\newenvironment{stylePi}{\setlength\leftskip{1.131cm}\setlength\rightskip{1.131cm}\setlength\parindent{0cm}\setlength\parfillskip{0pt plus 1fil}\setlength\parskip{0.559cm plus 0.0559cm}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0.559cm plus 0.0559cm}\par}
\newenvironment{styleCitationanglais}{\setlength\leftskip{1.131cm}\setlength\rightskip{1.131cm}\setlength\parindent{0cm}\setlength\parfillskip{0pt plus 1fil}\setlength\parskip{0.559cm plus 0.0559cm}\writerlistparindent\writerlistleftskip\begin{english}\leavevmode\normalfont\normalsize\normalcolor\writerlistlabel\ignorespaces}{\end{english}\unskip\vspace{0.559cm plus 0.0559cm}\par}
\newenvironment{styleCitationsuivant}{\setlength\leftskip{1.131cm}\setlength\rightskip{1.131cm}\setlength\parindent{0cm}\setlength\parfillskip{0pt plus 1fil}\setlength\parskip{0cm plus 1pt}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0.559cm plus 0.0559cm}\par}
\newenvironment{stylePiv}{\renewcommand\baselinestretch{1.0}\setlength\leftskip{0cm}\setlength\rightskip{0cm}\setlength\parindent{0cm}\setlength\parfillskip{0pt plus 1fil}\setlength\parskip{0cm plus 1pt}\writerlistparindent\writerlistleftskip\begin{french}\leavevmode\normalfont\normalsize\normalcolor\writerlistlabel\ignorespaces}{\end{french}\unskip\vspace{0cm plus 1pt}\par}
% List styles
\newcommand\writerlistleftskip{}
\newcommand\writerlistparindent{}
\newcommand\writerlistlabel{}
\newcommand\writerlistremovelabel{\aftergroup\let\aftergroup\writerlistparindent\aftergroup\relax\aftergroup\let\aftergroup\writerlistlabel\aftergroup\relax}
\newcommand\labellistListileveli{\textstyleNumberingSymbols{•}}
\newcommand\labellistListilevelii{\textstyleNumberingSymbols{•}}
\newcommand\labellistListileveliii{\textstyleNumberingSymbols{•}}
\newcommand\labellistListileveliv{\textstyleNumberingSymbols{•}}
\newenvironment{listListileveli}{\def\writerlistleftskip{\addtolength\leftskip{0.4cm}}\def\writerlistparindent{}\def\writerlistlabel{}\def\item{\def\writerlistparindent{\setlength\parindent{-0.4cm}}\def\writerlistlabel{\makebox[0.4cm][l]{\labellistListileveli}\hspace{0cm}\writerlistremovelabel}}}{}
\newenvironment{listListilevelii}{\def\writerlistleftskip{\addtolength\leftskip{0.801cm}}\def\writerlistparindent{}\def\writerlistlabel{}\def\item{\def\writerlistparindent{\setlength\parindent{-0.4cm}}\def\writerlistlabel{\makebox[0.4cm][l]{\labellistListilevelii}\hspace{0cm}\writerlistremovelabel}}}{}
\newenvironment{listListileveliii}{\def\writerlistleftskip{\addtolength\leftskip{1.199cm}}\def\writerlistparindent{}\def\writerlistlabel{}\def\item{\def\writerlistparindent{\setlength\parindent{-0.4cm}}\def\writerlistlabel{\makebox[0.4cm][l]{\labellistListileveliii}\hspace{0cm}\writerlistremovelabel}}}{}
\newenvironment{listListileveliv}{\def\writerlistleftskip{\addtolength\leftskip{1.6cm}}\def\writerlistparindent{}\def\writerlistlabel{}\def\item{\def\writerlistparindent{\setlength\parindent{-0.4cm}}\def\writerlistlabel{\makebox[0.4cm][l]{\labellistListileveliv}\hspace{0cm}\writerlistremovelabel}}}{}
% Footnote rule
\setlength{\skip\footins}{0.119cm}
\renewcommand\footnoterule{\vspace*{-0.018cm}\setlength\leftskip{0pt}\setlength\rightskip{0pt plus 1fil}\noindent\textcolor{black}{\rule{0.25\columnwidth}{0.018cm}}\vspace*{0.101cm}}
% Pages styles
\fancypagestyle{Standard}{\fancyhf{}
  \fancyhead[L]{}
  \fancyfoot[C]{\thepage{}}
  \renewcommand\headrulewidth{0pt}
  \renewcommand\footrulewidth{0pt}
  \renewcommand\thepage{\arabic{page}}
}
\fancypagestyle{FirstPage}{\fancyhf{}
  \fancyhead[L]{}
  \fancyfoot[L]{}
  \renewcommand\headrulewidth{0pt}
  \renewcommand\footrulewidth{0pt}
  \renewcommand\thepage{\arabic{page}}
}
\pagestyle{Standard}
\sloppy
\title{Le rôle de l’harmonie et de la musique dans le Timée de Platon}
\author{}
\date{2013-02-01}

正如您所见,它看起来不太干净,但我相信它会带来一些好处。我正在为我的研究中心开发的模板有一组类似的样式。

答案1

我需要知道的是:我可以将包含我需要的所有样式命令的前言转储到类文件中吗?

请不要也不要从 Writer2LaTeX 的计算机生成的序言中获取任何灵感。我的建议是,您应加强对 LaTeX 的了解,并按照以下方式开发自己的课程。

确保要求写在样式指南中。

尝试先编写样式指南或扩展现有样式指南以涵盖部门的所有排版要求。该指南应涵盖段落缩进、字体、字体大小、参考书目和引文、脚注、图表标题等内容。这应作为课程开发的书面规范。

熟悉课堂写作技巧。

其次,如果你不熟悉课堂写作,请复习一些现有的课程。我建议你选择 ctan 提供的标准课程类.dtx。我还建议您查看 tufte-book 类,该类是在不使用.dtx文件的情况下编写的。我个人倾向于使用docdocstrip方法来生成类,因为这可用于提供用户手册,以及以文学方式描述类以简化未来的维护和版本发布。该.dtx系统还足够灵活,可以提供辅助类,例如文章或内部报告。您还可以让该类生成用于投影仪和讲义演示文稿的模板。

开始开发

完成上述操作后,您就可以开始对类进行编程,但还有最后一项活动。您需要定义允许用户更改论文排版的哪一部分。这些必须作为选项提供给类。对于论文,您可能希望限制这种灵活性,因为我猜想一致性至关重要。您还需要仔细检查您的需求,以决定要与该类一起加载哪些包。一旦您收集了所有这些信息,我自己的偏好是修改现有的book类,而不是选择一个更框架类,例如memoir。我发现基础book类结构非常好,是学习更多有关 LaTeX 类开发的好方法。您决定使用 XeLaTeX 或 LuaTeX 是很好的,尽管我个人会选择 XeLaTeX。但是,通过检查底层引擎并为所有不同的引擎提供后备代码,使您的类具有通用性(请参阅代码tufte-book以获得灵感)。

版本控制和备份

使用 Git 和 Github 或类似服务来管理修订,使用 Dropbox 进行备份或使用您熟悉的任何其他系统。由于您将使用 XeLaTeX 或 LuaTeX,因此还必须为一些正在积极开发的软件包(例如及其fontspec依赖项和)创建一个存储库polyglossia

还要走多远? 许多框架类似类提供了太多的灵活性,无法满足您的需求。就您的情况而言,您需要实现一种非常具体的样式。让您的类尽可能地防弹。祝您好运,并引用 Knuth 的话:

一开始只有一位用户,我花了很多时间才让自己满意。然后我有了 10 位用户,又出现了一个全新的困难。然后我有了 100 位用户,又发生了另一个层次的事情。我有一千位用户,有一万位用户,这些都是开发过程中的特殊阶段,很重要。在完成一千位用户之前,我不可能完成一万位用户。但每次出现新的变化时,我们的想法都是让 TeX 变得更好,而不是变得更加多样化,因为它需要处理新事物。

注意:我稍后会回来并添加一些关于一些更技术方面的链接。

相关内容