The documents generated by the
LaTeX export function
can be customized by creating template files. A template file is a text file containing
special sections which are replaced by JGloss with the document content. Per convention,
template files use the
.tmpl
file ending. Example template files
can be found in the
latex/templates
folder of the JGloss distribution.
The first line in the template file is the encoding declaration .
%encoding: encoding_name
Valid encoding names are all encodings supported by the Java Runtime which is used.
(Not all encodings can represent Japanese characters or are supported by LaTeX-CJK/pLaTeX).
Some useful encodings are
EUC-JP
,
SJIS
or
UTF-8
. The encoding declaration determines both the character encoding
of the template file itself and the encoding used for the file generated from the template.
The encoding declaration line will not be copied to the generated file.
The second line gives a short description of the template. This line is optional.
%short-description: Text describing the template
The description will be displayed in the export dialog template chooser. The description line will not be copied to the generated file.
A longer description of the template can be given in a description block.
%description Template description line 1 Template description line 2 ... %end description
The description can appear once anywhere in the template, but it is suggested to place it
after the short description. The text will be displayed in the export dialog below the
template chooser when the template is selected.
%
and whitespace are stripped
from the beginning of a description line. Normal line breaks are ignored, to force a line break,
insert an empty line in the description block. The description block will not be copied to the
generated file.
The rest of the template is made of normal text, variables and insertion sections . Normal text is copied unchanged from the template file to the generated file. Variables have the form %variable-name% . In the generated file, variables are replaced by their values. A variable may appear anywhere in normal text and in pattern definitions (see below). In all text generated through variable substitution and for insertion sections, LaTeX special characters are properly escaped.
In the generated file, an insertion section in the template file is replaced by the document content. Insertion sections contain pattern definitions , which control the text generated for document elements like annotations or paragraphs. An insertion section has the following form:
%insertion-section-name %pattern-name1: pattern definition text %pattern-name2: pattern definition text ... %end insertion-section-name
The two insertion section types are
document-text
, which inserts
the text of the document with reading and translation annotations, and
annotation-list
, which inserts the list of annotations.
The
pattern definitions
control the text generation in insertion
sections. Pattern definitions can be given for readings, translations or paragraphs.
The pattern definition text is inserted for every occurrence of a pattern in the
insertion section, and special variables have different values for every application of
the pattern. To support insertion of line breaks and other special characters,
the pattern definition text may contain C-string-style escape sequences:
\n
inserts a line break,
\t
a tabulator and
\\
a single backslash.
For example, a pattern for occurrences of reading annotations may be defined
in a
document-text
insertion section.
%document-text %reading: \\ruby{%word%}{%reading%} ... more pattern definitions ... %end document text
When the document text is inserted in the generated file, for every occurrence
of a reading annotation in the document, the variable
%word%
is set to the annotated word and
%reading%
is set to the reading
annotation. The pattern is then applied, and the pattern text with variables
substituted is written to the generated file.
Table B.1. Pattern definitions
Name | Function | Defined in | Default |
---|---|---|---|
reading
| Applied to every reading annotation in the document. |
document-text
| (none) |
translation
| Applied to every translation annotation in the document. |
document-text
,
annotation-list
| (none) |
line-break
| Applied to every line break in the document which is not a paragraph break. |
document-text
|
\\\\\n
|
paragraph-start
| Inserted at the start of every paragraph. Paragraphs in a JGloss document are assumed to be seperated by one or more empty lines. |
document-text
,
annotation-list
| (none) |
paragraph-end
| Inserted at the end of every paragraph. Paragraphs in a JGloss document are assumed to be seperated by one or more empty lines. |
document-text
,
annotation-list
|
\n\n
|
Table B.2. Variables
Name | Description | Defined in pattern |
---|---|---|
document-filename
| Replaced by the file name of the exported JGloss document. | (global) |
generation-time
| Replaced by the current time and date. | (global) |
document-title
| Replaced by title of the JGloss document. | (global) |
font-size
| Replaced by the font size selected in the export dialog. | (global) |
longest-word
| Replaced by the longest annotated Japanese word (dictionary form) in the JGloss document. | (global) |
longest-reading
| Replaced by the longest reading (dictionary form) in the JGloss document. | (global) |
word
| Replaced by the annotated word. |
reading
|
reading
| Replaced by the reading annotation of an annotated word. |
reading
|
dictionary-word
| Replaced by the dictionary form of an annotated word. |
translation
|
dictionary-reading
| Replaced by the dictionary form of the reading of an annotated word. |
translation
|
translation
| Replaced by the translation text of an annotated word. |
translation
|
paragraph-number
| Replaced by the current paragraph number. |
paragraph-start
|