``) instead. If this is your case, just set up these filters:
```
% Use semantic tags (strong, em, ins, del) instead visual (B, I, U, S)
%!postproc(html): '(?i)(?)b>' '\1strong>'
%!postproc(html): '(?i)(?)i>' '\1em>'
%!postproc(html): '(?i)(?)u>' '\1ins>'
%!postproc(html): '(?i)(?)s>' '\1del>'
```
RCFILE filter
++ (X)HTML: Make subscript/superscript text ++[html-super-sub]
Txt2tags doesn't have a mark for subscript or superscript text.
But you can make your own. Let's define the following two new marks
for them:
- **``^^text^^``** for superscript text
- **``,,text,,``** for subscript text
-
Using the same idea from the previous tip, we make two filters:
```
% The ^ need to be escaped by \
%!postproc(html): \^\^(.*?)\^\^ \1
%!postproc(html): ,,(.*?),, \1
```
Using this filters, ``^^upper^^ and ,,lower,,`` becomes
``upper and lower``.
Again, you can instead use the modern CSS powered version:
```
%!postproc(html): \^\^(.*?)\^\^ \1
%!postproc(html): ,,(.*?),, \1
% On the CSS:
% .textsup { vertical-align: super }
% .textsub { vertical-align: sub }
```
RCFILE filters
++ (X)HTML: Use a remote image ++[html-remote-image]
In txt2tags you have a mark for local images, but not for remote ones.
The trick here is to fool the program making it think your remote
image is local.
There are two ways of achieving this. The first uses a filter:
```
%!postproc(html): RemoteImage.jpg http://www.example.com/myimage.jpg
Hi, check out my picture: [RemoteImage.jpg].
```
So txt2tags will make the image tag ``
``
and the filter will change it to ``
``.
The other trick is cleaner to type, but relies on a txt2tags behavior
that may not work on future versions. Just protect the image address
with the [raw mark userguide/RawRawLineRawArea.html], from the
beginning to the last character before the dot:
``` Hi, check out my picture: [""http://www.example.com/myimage"".jpg].
Easy!
++ (X)HTML: Insert text for images ALT attribute ++[html-img-alt]
Txt2tags already puts an empty ALT="" attribute on all images, so all
you have to do is to fill it. PostProc comes for the rescue.
```
%!postproc(xhtml): '(?i)(city.jpg.*?alt=")' '\1this is my city'
%!postproc(xhtml): '(?i)(beach.jpg.*?alt=")' '\1a really nice beach'
Hello, this is a photo of my city: [city.jpg]
And this the beach near here: [beach.jpg]
```
This will be converted to:
```
Hello, this is a photo of my city:
And this the beach near here:
```
The PostProc rule is a
[regular expression http://en.wikipedia.org/wiki/Regular_expression]
that matches from the image filename until its ALT attribute contents
start. Don't worry if you don't understand these symbols. Just copy &
paste these lines to you text and change "**city.jpg**" by your image
filename and "**this is my city**" to the image's text. The rest remains
untouched.
++ (X)HTML: Insert custom tags (DIV, SPAN) ++[html-custom-tags]
From txt2tags version 2.6 and newer, there's a new tagged mark to
directly insert target code.
You can do it in blocks:
```
'''
This paragraph will live inside mycooldiv DIV.
But note that txt2tags marks are not interpreted here.
'''
```
In specific lines:
```
'''
This paragraph will live inside mycooldiv DIV.
Txt2tags marks are interpreted here.
'''
```
Or even inline, inside a paragraph:
``` My name is ''''John''''.
If you're using and older version of txt2tags, follow these tips:
You can combine the [Raw Line mark userguide/RawRawLineRawArea.html]
and a PostProc filter to insert any arbitrary (X)HTML tag you need.
First, decide which symbols you'll use to represent the ``<`` and
``>`` characters. A popular choice is ``{{`` and
% breaking line to avoid postproc expansion
``}}``. Then write your tags inside Raw Lines and it will work.
Example:
```
%!postproc(html): {{(.*?)}} <\1>
""" {{div id="mycooldiv"}}
This paragraph will live inside mycooldiv DIV.
""" {{/div}}
```
This will generate the following HTML code:
```
This paragraph will live inside mycooldiv DIV.
```
**Note:** The blank line after the paragraph is to make sure it will be closed before the DIV. If omitted, you'll end with tag overlap: ````.
++ (X)HTML: Use entities like é for accented characters ++[html-entities]
All modern browsers know how to handle accented characters, you don't need to use HTML entities like ``é`` or ``ã`` to represent them. Just type the accented letters normally.
The only thing you need to do, is to specify the correct encoding of your source file. You can use the txt2tags ``--encoding`` option or ``%!encoding`` directive. Examples:
```
% My source file is encoded in UTF-8
%!encoding: UTF-8
% My source file is encoded in latin-1 (ISO-8859-1)
%!encoding: iso-8859-1
```
If you really need the entities, for some exotic reason or system limitation, you can convert the accented chars using filters. If you use just a few accented chars, create one filter for each letter (lower and uppercase):
```
% Convert accented chars to HTML entities: é -> é
%!postproc(html): á á
%!postproc(html): â â
%!postproc(html): à à
%!postproc(html): ã ã
%!postproc(html): ä ä
%!postproc(html): Á Á
% ...
```
If you want a general solution for all accented vowels plus C-cedilla and N-tilde, use this set of filters:
```
% Convert accented vowels (plus Ç and Ñ) to HTML entities
%!postproc(html): ([ÁÉÍÓÚáéíóú]) &\1acute;
%!postproc(html): ([ÀÈÌÒÙàèìòù]) &\1grave;
%!postproc(html): ([ÄËÏÖÜäëïöü]) &\1uml;
%!postproc(html): ([ÂÊÎÔÛâêîôû]) &\1circ;
%!postproc(html): ([ÃÕãõ]) &\1tilde;
%!postproc(html): &[ÁÀÃÄÂ](\w+;) &A\1
%!postproc(html): &[áàãäâ](\w+;) &a\1
%!postproc(html): &[ÉÈËÊ](\w+;) &E\1
%!postproc(html): &[éèëê](\w+;) &e\1
%!postproc(html): &[ÍÌÏÎ](\w+;) &I\1
%!postproc(html): &[íìïî](\w+;) &i\1
%!postproc(html): &[ÓÒÖÔÕ](\w+;) &O\1
%!postproc(html): &[óòöôõ](\w+;) &o\1
%!postproc(html): &[ÚÙÜÛ](\w+;) &U\1
%!postproc(html): &[úùüû](\w+;) &u\1
%!postproc(html): Ñ Ñ
%!postproc(html): ñ ñ
%!postproc(html): Ç Ç
%!postproc(html): ç ç
```
RCFILE filters
++ (X)HTML: Split the page in multiple files ++[html-custom-tags]
All you have to do is to normally convert your file to (X)HTML with
txt2tags, then use the excellent HTMLDOC tool to split it. Example:
``` htmldoc -t htmlsep -o output-folder file.html
You can get full instructions on how to install and use HTMLDOC with
txt2tags on
[this Blog post http://txt2tags.wordpress.com/2006/08/31/split-html-in-multiple-pages/].
++ (X)HTML: Convert HTML pages to the txt2tags markup ++[html-to-t2t]
If you're migrating your site to txt2tags, there's a handy Vim script to convert all your HTML files to the simple t2t markup.
- First download the [unhtml.vim tools/unhtml.vim] script, or get it from the txt2tags "extras" folder.
- Then open one HTML file on the [Vim editor http://www.vim.org] and execute the following command:
``` :source /path/to/unhtml.vim
- A new txt2tags file named ``.html.t2t`` will be saved. Check its contents and correct by hand any mistake.
-
Repeat this process to all your HTML files.
**Tip inside the tip:** You can comment line 85 if you want the script to preserve unknown tags. They are deleted by default. Just add a double quote at the line start:
```
" mmmmm, dangerous! it removes all remaining HTML tags
" %s,<[^>]*>,,ge
```
**Note:** The Vim editor is installed by default on Linux and Mac OS X. Windows users must download and install it to use this script.
++ Man: Change section number ++[man-section]
% Patrick Useldinger
By default txt2tags generates man pages for section 1 (user commands).
But your man page can use any of these sections:
|| Nr. | Topic |
| 1 | Commands available to users
| 2 | Unix and C system calls
| 3 | C library routines for C programs
| 4 | Special file names
| 5 | File formats and conventions for files used by Unix
| 6 | Games
| 7 | Word processing packages
| 8 | System administration commands and procedures
To change the man section number, use this PostProc filter:
``` %!postproc(man): "^(\.TH.*) 1 " "\1 5 "
Change the number "5" to the desired section number. Attention to the white spaces. Cut & paste this line to make sure it is correct.
RCFILE filter
++ Man: Make the OPTIONS part of the man page ++[man-options]
Man pages use a standard format to show a program's options. You can
make your man page looks exactly as the system's pages using
definition lists. Pay attention to the bold marks and leading spacing
on each definition term. Example:
```
= OPTIONS =
: **--dump-config**
print all the config found and exit
: **-h**, **--help**
print help information and exit
: **-V**, **--version**
print program version and exit
```
++ MagicPoint: Make a pause on the slide ++[mgp-pause]
You can use the strong bar (``=========``) to make a pause on the
current slide in MagicPoint. It's useful to show just the first part
of the slide, then you explain it, then you press the space bar and the
rest of the slide appears.
You can use as many pauses as needed, like one for each list item.
Example:
```
= My nice slide =
- Item one
====================
- Item two
====================
- Item three
====================
- Item four
-
```
%++ MagicPoint: Force a new slide without title ++[mgp-pause]
%A new page is created for every =title=, or ==subtitle==. So just
%divide your contents into sections, one for each slide.
%
%If you don't need the pause, you can map the strong bar to a page
%break:
% %!postproc(mgp): %pause %page\n\n\n
% 1st 3 lines are special for titles
++ LaTeX: Load extra packages (\usepackage) ++[tex-style]
You can load any LaTeX package into your document, just use the
Style directive. Example:
```
%!style(tex): amssymb
% The --style command line option is another alternative
```
This will create the ``\usepackage{amssymb}`` line on your document
Preamble. Multiple packages can be loaded in one single call:
```
%!style(tex): amssymb,booktabs,array,paralist
% Will turn into \usepackage{amssymb,booktabs,array,paralist}
```
Starting in txt2tags version 2.3.1, you can also define multiple style
calls, making it easy insert configuration for each package using
PostProc filters. Example:
```
%!style(tex): amssymb
%!style(tex): booktabs
%!style(tex): array
%!style(tex): paralist
% This will create four \usepackage lines
```
RCFILE configuration
++ LaTeX: Remove the current date ++[tex-date]
% by christoph.sobotka@utanet.at
In txt2tags, the third header line is often used for the document date. If you leave it blank, no date tag will be generated. But in LaTeX, when no date tag is found, it automatically shows the current date on the document cover. Some expect this behavior, some don't.
To force the document to have no date, you must leave an empty date tag on the LaTeX code: ``\date{}``. You can make it easily setting a PostProc filter:
```
%!postproc(tex): \\date{-} \date{}
```
And in you source files, just type an hyphen on the third line, for example:
% Txt2tags respect the LaTeX default behavior, just removing the \date{} tag and not explicity
```
My doc
John Doe
-
```
The filter will remove the hyphen, leaving the tag empty and then LaTeX won't print any date.
**Extra tip:** If your TeX processor complains about the missing Author tag, you can do a similar workaround setting up another filter:
```
%!postproc(tex): \\author{-} \author{}
```
RCFILE configuration
++ LaTeX: Set the language config (babel, inputenc) ++[tex-lang]
% by leorosa
For the text encoding (character set) just use the Encoding directive.
Then include the babel package in your document and create a PostProc
filter to insert the language for it. It's a three line wonder:
```
% Brazilian Portuguese configuration
%!encoding: iso-8859-1
%!style(tex): babel
%!postproc(tex): {babel} [brazil]{babel}
```
This will add two extra lines to the LaTeX Preamble:
```
\usepackage[latin1]{inputenc} % char encoding
\usepackage[brazil]{babel} % user defined package
```
Note that the IANA standard encoding names are automatically
translated to [the LaTeX equivalents userguide/Encoding.html]
(iso-8859-1 to latin1 on this example).
++ LaTeX: Use a personal style file (.sty) ++[tex-user-style]
% Bob Tennent
Create your own LaTeX user style file (say myrules.sty) with all the
packages and configuration you usually put inside the document
Preamble.
Then just use the Style directive pointing to your file. Remember to
include the relative path for the file, if it isn't on the same folder
as your txt2tags source file. The file must have the ``.sty``
extension. You can use as many files as your heart wishes. Example:
```
%!style(tex): ../../common.sty
%!style(tex): ../../pdfthings.sty
%!style(tex): projectrules.sty
```
**Note:** The support for multiple style files was added into txt2tags
version 2.3.1.
RCFILE configuration
++ LaTeX: Use symbols and Greek letters (µ « ® Ø) ++[tex-greek]
% Bob Tennent
In LaTeX you normally just use $\mu$ to represent the µ Greek letter. You can type the letter on the txt2tags sources and make a postproc to convert it to the LaTeX entity.
``` %!postproc(tex): "µ" "$\mu$"
You can create similar filters for all the Greek letters do you
normally use, as well for any other special encoded letter or symbol.
RCFILE filter
= Text Editors =[text-editors]
++ Vim: Convert the current file ++[vim-convert]
``` :!txt2tags %
The ! executes an external command and % expands to the current filename. Make sure you have set the ``%!target`` configuration on the file, so you don't have to type the ``-t`` option on the command line.
Note that Vim's command-line mode ":" has history, so you just have to type it once. For the next conversions just do:
``` :
If you want to preserve this history even when quitting Vim, put this line in your ``~/.vimrc``:
``` set viminfo='10,\"30,:40,%,n~/.viminfo
++ Vim: Handy mappings to convert files ++[vim-mappings]
//By Frank Mueller//
With this lines in your ``~/.vimrc``, you will have handy shortcuts to convert the current file to LaTeX, HTML and text:
```
map 2l :w:!txt2tags -t tex % ; xelatex %<.tex ; open %<.pdf
map 2h :w:!txt2tags -t html % ; open %<.html
map 2t :w:!txt2tags -t txt %
```
%!include: inc/footer.t2t