Configuration requires some knowledge of the ruby language. If you don’t already know ruby, ruby is a well designed, fully object-oriented interpreted language in the spirit of Smalltalk (but with a rather modern syntax) plus some features from Perl and Lisp/Scheme (e.g. continuations).
The configuration files are regular ruby files
and are loaded after requiring all the libraries necessary. Theses files
reside in the directory
“$HOME/.deplate/” or
“$USERPROFILE/deplate.rc/”.
If these directories are not found, the files are searched in
$WINDIR/deplate.rc/
or /etc/deplate.rc/
. Some
files are also looked for in the “datadir” (usually
something like /usr/share/deplate/
).
This directory may also contain custom modules or css files etc. On Win 2000/XP etc., $USERPROFILE is usually set to “C:\Documents and Settings\USERNAME\”. See also 17 for how to add new elements, particles, macros etc.
The user configuration directory should look like this:
deplate
)
deplate
snippets)
deplate
snippets)
If the user requests loading “MODULE”, deplate searches for “~/.deplate/mod/MODULE.rb” first, then in ruby site-library. If it was found and loaded, the file “~/.deplate/after/mod/MODULE.rb” will be sourced, too – if available.
deplate
calls the class method
Deplate::Core.user_setup
after processing the command line
argumend. It calls the instance method
Deplate#user_initialize
after the new instance of the
deplate
converter was created and initialized, right before
actually performing the conversion.
In general, configuration is done by patching ruby classes. In the following example, we
class Deplate::List::Itemize @rx = /^(([ \t]+)(#)[ \t]+)(.+)$/ end class Deplate::Formatter::LaTeX @@latexDocClass = "scrartcl" end
Here is another example from my personal “after/fmt/latex.rb” file.
class Deplate::Formatter::LaTeX def hook_pre_prepare_my_configuration suppl = @deplate.variables["suppl"] #1 suppl &&= "[" + suppl + "]" output_at(:pre, :user_packages, "\\usepackage#{suppl}{suppl}") t = @deplate.get_clip("title") #2 output_at(:pre, :body_title, "\\tmltitle{#{t.elt}}") if t a = @deplate.get_clip("author") output_at(:pre, :body_title, "\\tmlauthor{#{a.elt}}") if a d = @deplate.get_clip("date") output_at(:pre, :body_title, "\\tmldate{#{d.elt}}") if d end end
deplate
calls the methods
Deplate::Core.user_setup(options)
and
Deplate::Core#user_initialize
if they are defined in order
to provide a possibility to hook into the standard setup procedure.
Deplate::Core.user_setup
is called when starting
deplate
from the command line and before a instance of
Deplate::Core
was created. This method should be used to
set values in the options
structure or to permanently
require one of deplate
‘s modules.
Deplate::Core#user_initialize
is called after an instance
of Deplate::Core
was created and should be used to set
variables specific to this instance.
Usually, any word in CamelCase (a.k.a. wiki name) is turned into a
hyperlink. By default only the letters A-Z and a-z are allowed here in
order to minimize possible conflicts between different encodings and
different versions of ruby on different systems
with different locales in effect. If this doesn’t fit your needs,
maybe because you happen to write in a language other than English,
which is possible and maybe even likely, you might want to change this.
Add something like this with the new character sets to your
config.rb
file:
class Deplate::HyperLink @@uc = 'A-ZÄÖÜ' @@lc = 'a-zäöüßáàéèíìóòçñ' end # the following re-compiles the regexps for wiki names Deplate::HyperLink.setup
If you really don’t like simple wiki names and want to disable the all together, you can put something like this into your config.rb:
If you don’t want to configure deplate
using
ruby, you can put some settings into the
deplate.ini
file, which usually
resides in ~/.depate
and/or
#{PWD}/deplate.rc
. Themes can also
have their own ini files.
This file contains a sequence of commands. Each command must fit in one line. The following commands are allowed:
allow FLAGS
deplate
to do certain
things(see 4)
--OPTION
mod NAME
fmt NAME
clip NAME=VALUE
wiki NAME.SUFFIX=BASEURL
.SUFFIX
part is optional)
wikichars UPPERCHARS LOWERCHARS
app NAME=COMMANDLINE
Exec format error
error, this is
probably caused by a missing executable suffix. To avoid this error,
redefine the app and add a .exe
or similar to the name.
$ENV=VALUE
VAR=VALUE
<<MARKER\nTEXT...\nMARKER\n
) as long
as the smaller characters (“<<”) appear right after
the equals sign. Internally, a multi-line value is processed as array.
Although this may not always work as expected, you can also set some
options (as defined in
5.4) by prepending the
name with a colon (“:”) or by using the option
keyword:
option NAME~
option NAME!
option NAME?=true|false|yes|no|on|off
option NAME%=INTEGER
option NAME=VALUE
Lines beginning with one of *%#;
are considered comments.
Example 5.1: deplate.ini
; Disable simple wiki names --no-simple-names ; Load some standard modules mod de mod mark-external-urls mod colored-log ; Applications app dot=/somewhere/not/in/the/standard/path/dot app latex=latex_wrapper.sh ; Clips clip author=Thomas Link ; Options ; Enable full LaTeX, support for ruby code & external applications allow t x X ; By default, use only a subset of deplate's standard markup option input_def=deplate-restricted ; Create latex output by default option fmt=latex ; Wikis wikichars A-ZÄÖÜ a-zäöüßáàéèíìóòçñ wiki DEPLATE.html=http://deplate.sf.net/ ; Variables ;; HTML css=deplate.css topBar=<<---- [auto] MyOtherHomepage | http://www.homepage.org ---- ;; Save auxiliary files in a subdirectory (BASENAME_files) auxiliaryDirSuffix=_files
Most command line options correspond to fields in the (open) structure
Deplate#options
. You could thus make your choices permanent
by adding something like this to your
config.rb
configuration file:
class Deplate::Core def self.user_setup(options) options.field_name = 'some value' # ok options.allow_exec = true # example end def user_initialize @variables['NAME'] = 'VALUE' # ok @options.other_field_name = 'some value' # deprecated end end
The variable options
is meant to
influence the whole setup and should contain variables that cannot be
set directly by a document. variables
are meant to specific
to the current conversion process. While options
should be
set in Deplate#user_setup, variables
should be defined in Deplate#user_initialize.
Here is a mostly complete table of command line options and corresponding option fields:
The command-line option “-x” or
“--allow-ruby [RUBY
SAFE]” currently sets the class variable
@@allow_ruby
and the global variable
$SAFE
(if an integer is provided). --verbose
sets Deplate’s class variable
@@verbose
.
deplate
supports two ways of page templates:
You can define a template in ruby by setting the following Deplate class variables:
@@pre_matter_template
@@body_template
@@post_matter_template
@@deplate_template
Typical use would be (in your
config.rb
file)
class Deplate def self.user_setup(options) if options.fmt =~ /^html/ @@post_matter_template[10] = ['<br>\n(c) 2004, Me'] end @@deplate_template << '#AU: My Name' end end
Via the -t
or --template
command-line option
or by setting the template
document
variable (see 15.1),
you can define simple text templates that will be filled in with content
from your deplate
file.
Since version 0.7, deplate
uses a specialized
formatter for handling templates. Before 0.7,
this was done by search & replace. If you have pre 0.7 templates
which don’t work any more, you can switch back to the old template
mechanism by setting the document
option template_version
to 1.
In templates, only a small number of statements are available:
The commands PREMATTER, POSTMATTER, BODY as well as the Mingle region are specific to templates.
PREMATTER, POSTMATTER, and BODY can be used to fill in formatted content
for an explanation of deplate
‘s document structure):
#PREMATTER
#BODY
#POSTMATTER
These commands take a list of slots (named or as numbers) as arguments. The slots can be single slots or ranges. They can be positive (add selectively) or negative (add with the exception of certain content). Examples:
#PREMATTER: -doc_def
#PREMATTER: doc_def mod_packages mod_head
#PREMATTER: head_beg..prematter_end
A slot cannot be consumed twice. I.e., if you use several template commands, the latter will not insert the content that was already inserted by the previous command.
The Mingle region can be used to add some text to a specific slot in the
original document. Filling in templates takes place after the document
was produced. A template actually processed by
deplate like normal text but with a different
active rule set. Thus, if you define a slot or a type for a region in
the template file these definitions refer to the template output which
usually is not quite what you want. You can use Mingle to make them
refer to the original document. See
html-left-tabbar-js.html
in the templates
subdirectory of the distribution for an example.
Curly braces in templates could cause problems because
deplate
maybe interpretes them as
macros. If deplate
mixes up your
template, you should prefix these curly braces that cause problems with
a backslash.
Backslashes have always to be doubled.
Example 5.2: A letter template
In this example, we use get for the author’s name because the corresponding clip is automatically defined by the standard #AU(THOR) command. For other data we use variables.
Template: tmpl_letter.tex
\\documentclass[12pt,a4paper,english]{letter} #PREMATTER: -doc_def \\address{{get: author}\\\\ {val escapebackslash!: address}} \\signature{{get: author}} \\begin{letter}{{val: addresseeName}\\\\ {val escapebackslash!: addresseeAddress}} \\opening{Dear {val: addresseeName},} #BODY \\closing{Sincerly,} \\vfill{} \\encl{{val: enclosure}} \\end{letter} #POSTMATTER
Input file: example-letter.txt
#AU: John Smith #DATE: today #VAR id=address: Cool Place 1{nl inline!}Hiptown 10000 #VAR id=enclosure: Important Document #VAR: addresseeName=Max Mustermann #VAR: addresseeAddress=Tolle Straße 2{nl}Neustadt 20000 I would like to say thanks for your last letter which I read with much joy. I hope to be hearing from you soon.
Command line:
deplate -t tmpl_letter.tex -f latex example-letter.txt pdflatex example-letter.tex
Result: example-letter.pdf