How is this information converted to TeX? Our xml2tex library is for us a natural choice for several reasons: it provides a schema-independent grammar for transforming XML into TeX, and it includes built-in libraries for handling formulas and tables, eliminating the need for custom solutions. Moreover, it seamlessly integrates with our xerif typesetting system.
As in CSS, in TeX some formatting information is inserted inline into the text, while others are typically declared in an external style file. For example, there are general formatting rules that specify the layout of the page and other rules that set a portion of text in italics. For this reason, Christine needed to analyze these layers and separate them systematically. Thankfully, xml2tex is able to declare different outputs with one configuration, e.g. a TeX file and a style file.
So, we decided to generate a xml2tex configuration with XSLT by analyzing XHTML/CSSa and CSS XML. The first part of the generated configuration is the creation of the TeX style file. Paper format, font declarations, font styles, headline elements (h1…h6), etc. are evaluated and the respective TeX macros are created. To align with xerif , the TeX style includes many instructions from our CoCoTeX framework. For example, by analyzing the size property of the @page
rule above, this TeX snippet is created:
<template context="/html:html/html:head/(html:style|html:link)[1]"> <file href="file:///home/cwindeln/printcss2tex/tmp/printcss.sty" encoding="utf-8"> % (...) \setlength{\pagewidth}{210mm} \setlength{\pageheight}{297mm} % (...) </file> </template>
The second part of the configuration is generated by analyzing the CSS declarations and creating xml2tex templates from it. The xml2tex template below is generated from a declaration which sets the font size for <p>
elements:
<template context="*:p"> <text>{\fontsize{11.5pt}</text> <xsl:next-match xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/> <text>}</text> </template>
During the implementation, Christine noticed that there is no equivalent for the CSS selectors ::before
and ::after
in TeX. Therefore, we decided to create placeholder elements before, into which we can later generate the content using xml2tex. The entire transformation is organized into distinct steps, as illustrated below:
Parse the CSS and generate CSS XML and XHTML/CSSa
Insert pseudo elements for content that is inserted with the CSS selectors ::before
and ::after
Generate a xml2tex configuration from CSS XML and XHTML/CSSa
Use xml2tex with the generated configuration and apply it on the XHTML/CSSa document to create TeX and the style file.
Render the TeX file with LuaTeX
Figure 1. Figure 1: The transformation of XHTML and CSS to TeX