draft_api.texi 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. @node texi2any Output Customization
  2. @chapter @command{texi2any} Output Customization
  3. @cartouche
  4. @quotation Warning
  5. The information displayed here is likely to change in the future.
  6. In particular, the functions and their behavior may change in any
  7. Texinfo release.
  8. @end quotation
  9. @end cartouche
  10. This chapter describes how to customize aspects of the
  11. @command{texi2any} HTML output. Although some of the features here
  12. can technically be used with other output formats, it's not especially
  13. useful to do so, so we'll write the documentation as if HTML were the
  14. target format. Most of the customizations are only available for
  15. HTML.
  16. This part of the manual and the corresponding interfaces are being
  17. stabilized, and the only parts described are those that should not
  18. change in the future. Many other aspects of the formatted HTML may
  19. already be customized, but the interfaces will change and will be
  20. documented as soon as they are stable.
  21. The HTML converter takes a Texinfo Perl tree as input and transforms
  22. it to HTML@. The Texinfo Perl tree describes a Texinfo document in a
  23. structured way which makes it easy to go through the tree and format
  24. @@-commands and other containers. The code that is used to go through
  25. the tree cannot be customized, but the conversion of tree elements can
  26. be fully customized. The tree structure and the customization of
  27. Texinfo Perl tree elements will be described in future versions of the
  28. manual.
  29. @menu
  30. * Loading Init Files:: Finding and writing initialization files.
  31. * Init File Basics:: What init files can contain and do.
  32. @end menu
  33. @node Loading Init Files
  34. @section Loading Initialization Files and Search Paths
  35. @cindex Loading init files
  36. @cindex Initialization files, loading
  37. @cindex Search paths, for initialization files
  38. @pindex Config @r{init files loaded}
  39. You can write so-called @dfn{initialization files}, or @dfn{init
  40. files} for short, to modify almost every aspect of output formatting.
  41. The program loads init files named @file{Config} each time it is run.
  42. Those files are looked for in the following directories:
  43. @table @file
  44. @item @var{datadir}/texi2any/
  45. (where @var{datadir} is the system data directory specified at
  46. compile-time, e.g., @file{/usr/local/share})
  47. @item @var{sysconfdir}/texi2any/
  48. (likewise specified at compile time, e.g., @file{/usr/local/etc})
  49. @item ~/.texi2any/
  50. (where @code{~} is the current user's home directory)
  51. @item ./.texi2any/
  52. (under the current directory)
  53. @item ./
  54. (the current directory)
  55. @end table
  56. All @file{Config} files found are loaded, in the above order. Thus,
  57. @file{./Config} can override entries in, say,
  58. @file{/usr/local/share/makeinfo/Config}.
  59. @opindex --init-file
  60. However, the most common way to load an initialization file is with
  61. the @option{--init-file} option, explicitly specifying the file to be
  62. loaded. By default the following directories are searched, in the
  63. following order.
  64. @c where @var{prog} is the name of the program invoked
  65. @c on the command line (@command{makeinfo}, @command{texi2any}, etc.).
  66. Only the first file found is used:
  67. @enumerate
  68. @item The current directory @file{./};
  69. @item @file{./.texi2any/} under the current directory;
  70. @item @file{~/.texi2any/}
  71. where @code{~} is the current user's home directory;
  72. @item @file{@var{sysconfdir}/texi2any/}
  73. where @var{sysconfdir} is the system configuration directory
  74. specified at compile-time, e.g., @file{/usr/local/etc};
  75. @item @file{@var{datadir}/texi2any/}
  76. Where @var{datadir} is the system data directory likewise specified at
  77. compile time, e.g., @file{/usr/local/share};
  78. @item @file{./.texinfo/init/} under the current directory;
  79. @item @file{~/.texinfo/init/} under the current home directory;
  80. @item @file{@var{sysconfdir}/texinfo/init/} with @var{sysconfdir} as above;
  81. @item @file{@var{datadir}/texinfo/init/} with @var{datadir} as above.
  82. @end enumerate
  83. Additional directories may be prepended to the list with the
  84. @option{--conf-dir} option (@pxref{Invoking texi2any}).
  85. @node Init File Basics
  86. @section Init File Basics
  87. @cindex Init file basics
  88. @cindex Perl, language for init files
  89. Init files are written in Perl, and by convention have extension
  90. @file{.init} or @file{.pm}.
  91. @c Several init files are included in the Texinfo
  92. @c distribution (some are crucial components of the program), and can
  93. @c serve as a good model for writing your own.
  94. @c Smaller examples include @file{utf8.pm},
  95. @c @file{html32.pm}, and plenty more.
  96. @menu
  97. * Init File Namespaces:: @code{Texinfo::Config}.
  98. * Setting and Getting Customization Variables::
  99. * Internationalization of Strings::
  100. @end menu
  101. @c * Init File Expansion Contexts:: Normal, preformatted, string, math.
  102. @node Init File Namespaces
  103. @subsection Init File Namespaces
  104. @cindex Init file namespaces
  105. @cindex Namespaces, for init files
  106. @cindex Perl namespaces, for init files
  107. @c when colons are supported ... vindex Texinfo::Config @r{namespace}
  108. Initialization file are loaded from the main program via an
  109. @code{require} call in the @code{Texinfo::Config} namespace. This
  110. means that the namespace of the main program and the namespace of
  111. initialization files are distinct, which minimizes the chance of a
  112. name clash.
  113. @node Setting and Getting Customization Variables
  114. @subsection Setting and Getting Customization Variables
  115. @cindex Customization variables, setting and getting
  116. The basic operations on customization variables are to set and
  117. retrieve their values.
  118. To set the value of a customization variable from an initialization
  119. file, you should use @code{set_from_init_file}:
  120. @defun set_from_init_file ($variable_name, $variable_value)
  121. @var{$variable_name} is a string containing the name of the variable
  122. you want to set, and @var{$variable_value} is the value to which you
  123. want to set it. @var{$variable_value} may be @samp{undef}.
  124. @end defun
  125. For example,
  126. @example
  127. set_from_init_file('documentlanguage', 'fr');
  128. @end example
  129. @noindent overrides the @code{@@documentlanguage} from the
  130. document. It would be overridden by @option{--document-language} on
  131. the command line.
  132. Another example:
  133. @example
  134. set_from_init_file('SPLIT', 'chapter');
  135. @end example
  136. @noindent overrides the default splitting of the document. It would be
  137. overridden by @option{--split} on the command line.
  138. A final example:
  139. @example
  140. set_from_init_file('NO_CSS', 1);
  141. @end example
  142. @noindent overrides the default value for @code{NO_CSS}. It would be
  143. overridden by @code{--set-customization-variable NO_CSS=1} on the command line.
  144. To get the value of a variable, the function is @code{get_conf}:
  145. @defun get_conf ($variable_name)
  146. @var{$variable_name} is the name of the variable; its value (possibly
  147. @code{undef}) is returned.
  148. @end defun
  149. For example:
  150. @example
  151. if (get_conf('footnotestyle') eq 'separate') @{ ... @}
  152. @end example
  153. For the customization variables associated with @@-commands, see
  154. @ref{Customization Variables for @@-Commands}. For the customization
  155. variables associated with command line options, see @ref{Customization
  156. Variables and Options}.
  157. @ignore
  158. @c The following is still true, but right now nothing uses these contexts
  159. @c in init files.
  160. @c
  161. @c @node Init File Expansion Contexts
  162. @c @subsection Init File Expansion Contexts: Normal, Preformatted, String, Math
  163. @c
  164. @c @cindex Init file expansion contexts
  165. @c @cindex Expansion contexts, for init files
  166. @c @cindex Contexts for expansion in init files
  167. @c
  168. @c There are four expansion contexts of interest:
  169. @c
  170. @c @table @emph
  171. @c @item normal context
  172. @c @cindex Normal expansion context
  173. @c Paragraphs, index entries, tables, @enddots{}
  174. @c
  175. @c @item preformatted context
  176. @c @cindex Preformatted expansion context
  177. @c When spaces between words are kept. For example, within the
  178. @c @code{@@display} (@pxref{display,, @code{@@display}}) and
  179. @c @code{@@example} environments (@pxref{example,, @code{@@example}}), and
  180. @c in menu comments. The preformatted regions
  181. @c are usually rendered using @code{<pre>} elements in HTML.
  182. @c
  183. @c @c oldapi (@pxref{Menu formatting})
  184. @c
  185. @c @item string context
  186. @c @cindex String expansion context
  187. @c When rendering strings without formatting elements, for example in
  188. @c comments (@pxref{Comments}) and titles. In the string context, there
  189. @c is limited formatting, typically without any element when producing HTML,
  190. @c so the value can be used in an attribute.
  191. @c
  192. @c @item math context
  193. @c @cindex Math expansion context
  194. @c Math (@pxref{math,, @code{@@math}}).
  195. @c
  196. @c @end table
  197. @end ignore
  198. @node Internationalization of Strings Function
  199. @subsection Internationalization of Strings in the Output Document Function
  200. @vindex texinfo_document @r{Gettext domain}
  201. The subroutine @code{gdt} is used for translated strings:
  202. @defun gdt (\%converter, $string, \%variables_hash)
  203. @var{$string} is the string to be translated, @var{\%variables_hash}
  204. is a hash reference holding the variable parts of the translated
  205. string, and @var{\%converter} is an object which holds the informations
  206. about the context. The result returned is a perl Texinfo tree.
  207. @end defun
  208. When the string is expanded as Texinfo, and converted to a
  209. Texinfo tree in perl, the arguments are substituted; for
  210. example, @samp{@{arg_name@}} is replaced by the corresponding
  211. actual argument, which should be Texinfo perl trees or Texinfo
  212. perl tree contents arrays.
  213. In the following example, @samp{@{date@}}, @samp{@{program_homepage@}}
  214. and @samp{@{program@}} are the arguments of the string. Since they
  215. are used in @code{@@uref}, their order is not predictable.
  216. @samp{@{date@}}, @samp{@{program_homepage@}} and @samp{@{program@}} are
  217. substituted after the expansion, which means that they should already be
  218. Texinfo perl trees or Texinfo perl tree contents:
  219. @example
  220. gdt('Generated on @@emph@{@{date@}@} using
  221. @@uref@{@{program_homepage@}, @@emph@{@{program@}@}@}.',
  222. @{
  223. 'date' => expand_today(\%converter),
  224. 'program_homepage'
  225. => @{'text' => $Texi2HTML::THISDOC@{'program_homepage'@}@},
  226. 'program'
  227. => @{'text' => $Texi2HTML::THISDOC@{'program_and_version'@}@} @},
  228. );
  229. @end example