Customization The transformation process (and thus the output rendering) can be heavily customized by: using some configuration parameters either in a configuration stylesheet or directly from the command line, using Processing Instructions to create some instructions very specific to dblatex, using some customized stylesheets, using a customized LaTeX style package. using a LaTeX post process script or plugin. All these customization methods can be used independently and in exceptional cases, but it can also be combined and registered in a master configuration file, called a specification file (cf. ) to create a new tool dedicated to your needs.
Using XSL Parameters The PDF rendering can be customised by using some XSL configuration parameters. contains the reference documentation of the available user-configurable parameters.
Setting Command line Parameters You can set some XSL parameters directly from the command line without creating a configuration parameter stylesheet, with the option. The following example set the latex.hyperparam parameter value:
Using Processing Instructions Dblatex has Processing Instructions (PI) which can modify the default document formatting. Usually these instructions alter the output formatting of specific DocBook elements, like table cells. To alter formatting globally it is better to set an appropriate stylesheet parameter. Processing instructions are written <?name content ?>. Most often content will have the form of one or more XML attributes with a value, as follows: <?name attribute="value" ?>. The list of the available Processing Instructions are given in . Here is an example of a PI used in a table: Table width specified with a Processing Instruction
XSL User Stylesheet You can provide your own XSL stylesheet to set some of the XSL parameters, and/or to override some of the dblatex XSL templates. The user stylesheet is specified by using the option .
Changing the XSL parameter values The parameters can be stored in a user defined XSL stylesheet. An example of configuration stylesheet is given with this manual:
Overriding some templates You can directly put the overriding templates in your XSL stylesheet, but do not try to import the default dblatex stylesheets in it: it is automatically done by the tool. So, just focus on the template to override and dblatex will ensure that your definitions will get precedence over the dblatex ones. You can of course split your templates in several files, and import each of them in the main user stylesheet by calling xsl:import. Overriding templates \let\mymacro=\DBKrelease ]]>
Customized LaTeX style The actual output rendering is done by the latex style package used, and not by the XSL stylesheets whose role is only to translate to latex. Users can provide their own LaTeX style file, in respect of some rules: The LaTeX style package preamble must support all the options that the XSL stylesheets can pass to the package. Some packages must be used to make all the thing work. The docbook interface must be defined: the XSL stylesheets register some elements information in LaTeX commands. These commands or macro are the only ones specific to DocBook that are explicitely used by the XSL stylesheets. Other specific macros are used but are not intended to be changed by the user. These hidden macros are defined in the dbk_core latex package. The latex style file to use is specified by using the option . An example of a simple LaTeX DocBook style is provided in the package. The option accepts a package name (no path and no .sty extension) or a full style file path. If a full path is used, the filename must ends with .sty. # Give a package name and assume its path is already in TEXINPUTS dblatex --texstyle=mystyle file.xml # Give the full package path. The TEXINPUTS is then updated by dblatex dblatex --texstyle=./mystyle.sty file.xml
Reusing an existing LaTeX style You can either create your latex style from scratch, in respect of the interfaces described in the following sections, or you can simply reuse an already existing style and override what you want. The latter method is easier for small things to change. Here is an example of a style package reusing the default docbook style: Reused LaTeX style
Package options A compliant LaTeX style package supports the following options. The options are provided by the XSL stylesheets according to the document attributes.
Needed packages A LaTeX style package must at least include the following packages.
DocBook interface All the latex commands beginning with DBK are related to elements under bookinfo or articleinfo.
Latex post process script Extra user actions can be processed on the latex file produced by the XSL stylesheets or on its temporary working files produced by the latex compilation. For instance, in the documents I write the cover page must display the number of pages of the document, but written in full letters (e.g. 23 is written “twenty three”). The latex post process script is then helpfull, and in this particular case it patches the .aux file. The post process script is called just before the last latex compilation, and takes one parameter, the latex file compiled by the tool.
Post latex compilations The latex compilations done once the script is called depend on the return code of the script: When the return code is 0, dblatex continues the compilation as many times as necessary. When the return code is 1, no more compilation is done by dblatex. This case is useful if the script needs to control precisely the number of compilation to apply. It is up to the script to perform the expected compilations. To do so, the script can retrieve in the LATEX environment variable the actual compiler used by dblatex. When the return code is another value, an error is raised to signal a failed post process script execution.
Post processing with a Python Plugin You can use a python plugin instead of a script by prefixing the plugin name with the string "plugin:". When using a plugin you must not put the python suffix in the plugin name. If the plugin is in one of the Python system directories, or in the current directory where you call dblatex, or in one of the directories of the PYTHONPATH environment variable, you don't need to specify a directory location. Otherwise put the plugin directory path before the plugin name. Here are several plugin call examples: The plugin must contain a main entry point. Dblatex will pass the following parameters to the entry point: latex_file to specify the latex file to post process, and stdout to specify the output stream to use to be consistent with the dblatex verbosity. Texpost Python Plugin Example >stdout, "Plugin called on '%s' file" % (latex_file) # Open the latex file and parse it texfile = open(latex_file) ... # Now decide if a new compilation must occur if has_changed: sys.exit(0) else: sys.exit(1) ]]>
Dblatex Configuration File A configuration file, also called a specification file, can be used to list all the customizations and options to apply. Such a file is passed by using the option . Several configuration files can be specified if needed; it can be usefull to have a default setup and additional setup for specific needs that override or complete the default configuration.
XML Configuration File Format You should use the XML format to configure dblatex. It contains more features than the text format used up to the 0.3.7 release that is now deprecated. The principle remains the same, that is, most of the configuration parameters correspond to a command line option. Here is a full example of a configuration file. In the next sections the meaning and use of the configuration tags are detailed. Another example, much simpler, is the configuration file used for this manual. User Manual Configuration File The following sections detail the meaning of each tag. Note that dblatex provides some schema that you can use to validate your configuration file.
<sgmltag><config></sgmltag> It is the root element of a configuration file. A valid configuration file must have a config root element. Attributes: xmlns The namespace to use for a dblatex configuration file is: http://dblatex.sourceforge.net/config. The following elements occur in config: , , , .
<sgmltag><latex></sgmltag> The latex element contains the configuration data related to the latex processing. Attributes: none The following elements occur in latex: backend It defines the latex engine to use, like the option does. The backend name is specified through the use attribute. texstyle It defines the docbook latex style to use, like the option does. The latex package is specified through the use attribute. texpost It defines the latex post-processing script to use, like the option does. The script name is specified through the use attribute or the fileref attribute. indexstyle It defines index style file (.ist) to use, like the option does. The filename is specified through the fileref attribute. texinputs The element text defines the extra paths to add to TEXINPUTS, like the option does. bibinputs The element text defines the lookup paths of BIBINPUTS, like you would do by successive use of the option . bstinputs The element text defines the lookup paths of BSTINPUTS, like you would do by successive use of the option .
<sgmltag><xslt></sgmltag> The xslt element contains the configuration data related to the XSL processing. Attributes: none The following elements occur in xslt: stylesheet It defines a user stylesheet to use, like the option does. The stylesheet name is specified through the fileref attribute. If several stylesheet elements are set, the precedence is the same like using the option several times. engine See .
<sgmltag><engine></sgmltag> It defines the XSLT processor to use; it can be either a predefined engine, or a user-defined command to run. When the attribute use is used, it works like the option . The engine name is specified through the use attribute. When the element contains the command or commandchain child element it defines the command(s) to run to perform the XSLT processing. The core keywords defined in apply. The additional keywords of an XSLT engine command are the following: %(xmlfile)s Replaced by the XML source file to process. %(stylesheet)s Replaced by the stylesheet to use to process the XML file xmlfile. %(param_list)s Replaced by the list of the XSL parameters to set. The parameter pair formatting (the parameter name and its value) is specified through the param-format attribute given to the engine element. Attributes: param-format This attribute is mandatory when the engine is specified through a command. It tells how a parameter name and value pair shall be formatted when added to the XSLT engine command. The formatting is given by a string containing the keywords replaced by the name or value of the parameter to set: %(param_name)s Replaced by the name of the parameter to set. %(param_value)s Replaced by the value to set to the parameter. The following example re-writes with a user-defined command the Saxon engine with an additional option: saxon-xslt -T -o %(output)s %(xmlfile)s %(stylesheet)s %(param_list)s ]]>
<sgmltag><imagedata></sgmltag> The imagedata element contains the rules and commands to convert on the fly the images included in the docbook document. Attributes: none The following elements occur in imagedata: figpath It defines a path where to find the images, like the option does. figformat It defines the default image format when no suffix is available to deduce the actual format, like does. formatrule It specifies in which format an image must be converted, depending on the context, given by some attributes: docformat The output document for which the rule applies. When not set the rule applies for any format backend The rule applies only when this backend is used dst When the conditions are met the image shall be converted to this format. The following example: ]]> tells that when a PDF document is built with the xetex backend, the graphics not natively supported shall be converted to PDF. converter It defines an image transformation rule. See for more details.
<sgmltag><converter></sgmltag> The converter element defines a rule about how to convert on the fly an image in a docbook document to the corresponding image used in the built latex file. The goal is to have an image format compatible with the latex engine, whatever the original format is. Dblatex has a default set of rules, but one can overwrite or add some rules. Attributes: src Format of the original image referenced in the XML document. The converter only applies to the images matching this format. dst Target format once converted. The converter only applies to the original images having the format src and that need to be converted to the format dst. dst can take the special value "*" meaning that the rule applies for all the possible target formats (e.g. eps, pdf, png). docformat Specify for which document output format the converter applies. For example, if docformat is set to "pdf", it means that the converter applies only if the document output format is PDF. The converter will not apply if you want to build a PostScript or DVI document. backend The converter applies only if it is this latex engine that is used. For example, it is usefull if you want to convert an image in a specific way only when xetex is used. The following elements occur in converter: commandchain List of the commands to run. A commandchain contains one or more command elements. command command to execute to perform the conversion, or a part of the conversion if several commands are chained. See .
<sgmltag><command></sgmltag> The command element contains the arguments of the command to run. The arguments can contain some predefined keywords that are replaced by the actual values when the command is executed. The known core keywords are: %(src)s Replaced by the src value (original image format). %(dst)s Replaced by the dst value (target image format). %(input)s Replaced by the input file required by the command. In the case of an image conversion, it is the filename of the original image to convert. %(output)s Replaced by the name of the ouput file required by the command. In the case of an image conversion, it is the filename of the output image once converted. Attributes: input Standard input of the command to run. It can specify a file or it can specify to use the output of the preceding command if the keyword "PIPE" is used. output Standard output of the command to run. It can specify a file or it can specify that the output shall be redirected to the next command if the keyword "PIPE" is used. shell When set to "1" or "true", the command is run in a shell environment.
<sgmltag><options></sgmltag> The options element lists the extra arguments to pass to dblatex.
Deprecated Text Configuration File Format The format of the file is the following: Every comment starts with a “#”, and is ignored. The file must contain one parameter by line. The format of a parameter is the following: : ]]> Every parameter is mapped to an option that can be passed to dblatex. An unknown parameter is silently ignored (the whole line is dropped). The parameters defining a path (a file or a directory) can take absolute or relative paths. A relative path must be defined from the specification file itself. For instance, a specification file under /the/spec/directory/ with a parameter describing the file ../where/this/file/is/myfile points to /the/spec/where/this/file/is/myfile. The following table lists the supported parameters and the corresponding command line option.
Style Paths By default dblatex tries to find the configuration files related to a style (specified with option ) in the following paths, in respect of the order: The current directory $HOME/.dblatex /etc/dblatex The dblatex package configuration directories. You can add some extra paths where to look for by setting the DBLATEX_CONFIG_FILES environment variable. The paths are separated by ":" in Unix like systems, and by ";" on Windows. These paths are used only when nothing is found in the default paths.
Customization Precedence All the customization queries are translated to the corresponding command line options. Thus, using several customization methods can be unconsistent because each of them override the same option with another value. For instance, you can specify the use of a specification file in which it is said to use a latex style (parameter TexStyle) and explicitely use the command line option. So, what is the behaviour? The options order is the following: If a specification file is used ( option), the options are set to the specification file parameters. If several specification files are used ( option), the precedence is given to the last specified files. The options explicitely passed override the specification file setting, whatever is the position of the options (i.e. before or after the option). If an option is passed several times, this is the last occurence that is used. Customization Precedence Let's consider the specification file containing the following parameters: -b pdftex ]]> And now the command line: The setting used is the following: “-b dvips” overrides “-b pdftex” set by the spec file. “-p file2.xsl” overrides “-p file1.xsl” since it is defined after, and overrides “file3.xsl” set by the spec file. “-s mystyle2” override “mystyle1” set by the spec file.