# xml2tex **Repository Path**: checkp2p/xml2tex ## Basic Information - **Project Name**: xml2tex - **Description**: No description available - **Primary Language**: Unknown - **License**: BSD-2-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-11 - **Last Updated**: 2024-12-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # xml2tex A library for converting arbitrary XML to TeX. ## setup and run xml2tex xml2tex is not a standalone tool but an XProc library which also depends on other modules. So you need a little setup to run it. First start with creating a project directory and cloning the modules from GitHub: ``` $ mkdir asyoulike && cd asyoulike $ git clone --recursive -b saxon98 https://github.com/transpect/calabash-frontend.git calabash $ git clone https://github.com/transpect/mml2tex.git $ git clone https://github.com/transpect/cascade.git $ git clone https://github.com/transpect/mml-normalize.git $ git clone https://github.com/transpect/xproc-util.git $ git clone https://github.com/transpect/xslt-util.git $ git clone https://github.com/transpect/xml2tex.git ``` Now we add an XML catalog to resolve the import URIs of the XProc modules. ```xml ``` Store this XML catalog file to `xmlcatalog/catalog.xml`. Now you just have to run calabash. ``` $ calabash/calabash.sh -i source=xml2tex/example/example.xml -i conf=xml2tex/example/conf-hubcssa.xml xml2tex/xpl/xml2tex.xpl ``` Alternatively, you can download a [release of docx2tex](https://github.com/transpect/docx2tex/releases) that uses this xml2tex library, or you can clone docx2tex recursively for the most current libraries. There, all the repos listed above are already included as submodules, and the XML Catalog is also present. ## Configuration xml2tex can be configured for any kind of XML format. A sample XML configuration file is stored in the `example` directory. A [RelaxNG schema](https://raw.githubusercontent.com/transpect/xml2tex/master/schema/xml2tex.rng) is located in the `schema` directory. You can use the schema to check if your configuration file is valid and some editors which support RelaxNG will provide code completion and tool tips. Here is an example for a very basic configuration: ```xml \documentclass{scrbook} \usepackage{graphicx} \usepackage{hyperref} \usepackage{multirow} \maketitle \printindex ``` ### Preamble The LaTeX preamble is constructed with the `preamble` element. Enter static text such as document class name, package declarations and other stuff you may need. ```xml \documentclass{scrbook} \usepackage{graphicx} \usepackage{hyperref} \usepackage{multirow} \usepackage{amsmath} \usepackage{amssymb} ``` ### Frontmatter If you want to put content after `\begin{document}` but before the XML is inserted, you can do this with the `front` element. Typical use cases might be the creation of a frontmatter. If you do not want to add static content, you can help yourself with a few bits of XSLT as shown below: ```xml \title{} \date{} \author{} ``` ### Backmatter If you want to put content right before `\end{document}`, you can use the `back` element for this purpose. ```xml \printindex ``` ### XML namespaces If your XML input document use XML namespaces, it's necessary to declare each namespace with a corresponding `ns` element. ```xml ``` Don't forget to use the declared namespace prefixes in the XPath expression of the context attribute. If a template don't match the considered XML nodes, it could be caused by a wrong namespace. * wrong: `context="para"` * right: `context="dbk:para"` ### Templates and Rules #### Templates Templates are considered to match a certain XML node with a XPath expression and convert its contents according to a Rule statement into a LaTeX instruction. A template is specified with a `template` element. ```xml ``` The `@context` attribute is used to specify the XML node which is processed by the template. A Template can contain zero or one `rule` child element. If no `rule` exists, the XML node specified by the `@context` attribute is dropped. Given this XML element… ```xml my headline ``` …the template above would generate this LaTeX code: ```xml \chapter{my headline} ``` #### Rules A rule is declared as child element named `rule` and is used to specify the LaTeX instruction. ```xml ``` The value of the `@type` attribute specifies the certain type of the LaTeX instruction. Permitted values are `cmd` for instructions such as `\chapter` and `env` for environments such as `\begin{itemize} … \end{itemize}`. The `@name` attribute describes the name of the LaTeX instruction. `@break-after` is used to control the line breaks after the element. This attribute is necessary to control the whitespace after regular paragraphs. #### Parameters, Options and Text A rule can contain three child elements: `text`, `param`, `option`, which define how the content of the current XML node is wrapped. The `param` element specifies that the contents of the current context XML node is wrapped with curly braces `{}`. `option` is used to wrap the content with brackets `[]`, hence `text` process it without any wrapper. Each of these elements can contain a `@select` attribute. This attribute is optional and can be used to specify an XML node within the current context. The example below shows how to use the `@select` attribute to construct the parameters of a LaTeX link instruction. ```xml ``` ### Storing separate files Some TeX packages rely on external configuration files. For this purpose, you can store the evaluated context of a `template` to a separate file. The following example shows briefly how to generate a separate BibTeX file from an XML bibliography. ```xml ``` ### Style Mapping Frequently, you just want to map one element to a specific TeX instruction. Therefore xml2tex provides a simple `style` mapping. The content is selected by a specific attribute value. Therefore, you have to declare the name of the attribute globally with `@style-attribute`. Within `style` you specify the attribute value with `@name`. With `@start` and `@end`, you define which text is put around the content. Note: use Unicode entities such as ` ` to insert line breaks or handle whitespace. In the example below, all elements with a `@role` attribute and the value `heading1` are converted to `\chapter{ … }`. ```xml