preconv - Man Page
prepare files for typesetting with groff
Synopsis
preconv | -h |
preconv | --help |
preconv | -v |
preconv | --version |
Description
preconv reads each file, converts its encoded characters to a form troff(1) can interpret, and sends the result to the standard output stream. Currently, this means that code points in the range 0–127 (in US-ASCII, ISO 8859, or Unicode) remain as-is and the remainder are converted to the groff special character form “\[uXXXX]”, where XXXX is a hexadecimal number of four to six digits corresponding to a Unicode code point. By default, preconv also inserts a roff .lf request at the beginning of each file, identifying it for the benefit of later processing (including diagnostic messages); the -r option suppresses this behavior.
In typical usage scenarios, preconv need not be run directly; instead it should be invoked with the -k or -K options of groff. If no file operands are given on the command line, or if file is “-”, the standard input stream is read.
preconv tries to find the input encoding with the following algorithm, stopping at the first success.
- If the input encoding has been explicitly specified with option -e, use it.
- If the input starts with a Unicode Byte Order Mark, determine the encoding as UTF-8, UTF-16, or UTF-32 accordingly.
- If the input stream is seekable, check the first and second input lines for a recognized GNU Emacs file-local variable identifying the character encoding, here referred to as the “coding tag” for brevity. If found, use it.
- If the input stream is seekable, and if the uchardet library is available on the system, use it to try to infer the encoding of the file.
- If the -D option specifies an encoding, use it.
- Use the encoding specified by the current locale (LC_CTYPE), unless the locale is “C”, “POSIX”, or empty, in which case assume Latin-1 (ISO 8859-1).
The coding tag and uchardet methods in the above procedure rely upon a seekable input stream; when preconv reads from a pipe, the stream is not seekable, and these detection methods are skipped. If character encoding detection of your input files is unreliable, arrange for one of the other methods to succeed by using preconv's -D or -e options, or by configuring your locale appropriately. groff also supports a GROFF_ENCODING environment variable, which can be overridden by its -K option. Valid values for (or parameters to) all of these are enumerated in the lists of recognized coding tags in the next subsection, and are further influenced by iconv library support.
iconv support
While preconv recognizes all of the coding tags listed above, it is capable on its own of interpreting only three encodings: Latin-1, code page 1047, and UTF-8. If iconv support is configured at compile time and available at run time, all others are passed to iconv library functions, which may recognize many additional encoding strings. The command “preconv -v” discloses whether iconv support is configured.
The use of iconv means that characters in the input that encode invalid code points for that encoding may be dropped from the output stream or mapped to the Unicode replacement character (U+FFFD). Compare the following examples using the input “café” (note the “e” with an acute accent), which due to its short length challenges inference of the encoding used.
printf 'caf\351\n' | LC_ALL=en_US.UTF-8 preconv printf 'caf\351\n' | preconv -e us-ascii printf 'caf\351\n' | preconv -e latin-1
The fate of the accented “e” differs in each case. In the first, uchardet fails to detect an encoding (though the library on your system may behave differently) and preconv falls back to the locale settings, where octal 351 starts an incomplete UTF-8 sequence and results in the Unicode replacement character. In the second, it is not a representable character in the declared input encoding of US-ASCII and is discarded by iconv. In the last, it is correctly detected and mapped.
Limitations
preconv cannot perform any transformation on input that it cannot see. Examples include files that are interpolated by preprocessors that run subsequently, including soelim(1); files included by troff itself through “so” and similar requests; and string definitions passed to troff through its -d command-line option.
preconv assumes that its input uses the default escape character, a backslash \, and writes special character escape sequences accordingly.
Options
- -h
- and --help display a usage message, while -v and --version show version information; all exit afterward.
- -d
Emit debugging messages to the standard error stream.
- -D fallback-encoding
Report fallback-encoding if all detection methods fail.
- -e encoding
Skip detection and assume encoding; see groff's -K option.
- -r
Write files “raw”; do not add .lf requests.
See also
Referenced By
groff(1), groff(7), grog(1), lowdown(1), lowdown-diff(1).