1 package SL::Template::Plugin::KiviLatex;
 
   4 use parent qw( Template::Plugin::Filter );
 
   6 use SL::Template::LaTeX;
 
  13   return $cached_instance ||= $class->SUPER::new(@_);
 
  19   $self->install_filter($self->{ _ARGS }->[0] || 'KiviLatex');
 
  25   my ($self, $text, $args) = @_;
 
  26   return $::locale->quote_special_chars('Template/LaTeX', $text);
 
  31   '<ul>'      => "\\begin{itemize} ",
 
  32   '</ul>'     => "\\end{itemize} ",
 
  33   '<ol>'      => "\\begin{enumerate} ",
 
  34   '</ol>'     => "\\end{enumerate} ",
 
  39   '<strong>'  => "\\textbf{",
 
  43   '<em>'      => "\\textit{",
 
  49   '<sub>'     => "\\textsubscript{",
 
  51   '<sup>'     => "\\textsuperscript{",
 
  53   '<br/>'     => "\\newline ",
 
  54   '<br>'      => "\\newline ",
 
  58   my ($self, $text, $args) = @_;
 
  60   return SL::Template::LaTeX->new->_format_html($text);
 
  63 sub required_packages_for_html {
 
  71 return 'SL::Template::Plugin::KiviLatex';
 
  80 SL::Template::Plugin::KiviLatex - Template::Toolkit plugin for
 
  81 escaping text for use in LaTeX templates
 
  85 From within a LaTeX template. Activate both Template::Toolkit in
 
  86 general and this plugin in particular; must be located before
 
  89   % config: use-template-toolkit=1
 
  90   % config: tag-style=$( )$
 
  93 Later escape some text:
 
  95   $( KiviLatex.format(longdescription) )$
 
 101 =item C<filter $text>
 
 103 Escapes characters in C<$text> with the appropriate LaTeX
 
 104 constructs. Expects normal text without any markup (no HTML, no XML
 
 105 etc). Returns the whole escaped text.
 
 107 =item C<filter_html $html>
 
 109 Converts HTML markup in C<$html> to the appropriate LaTeX
 
 110 constructs. Only the following HTML elements are supported:
 
 114 =item * C<b>, C<strong> – bold text
 
 116 =item * C<it>, C<em> – italic text
 
 118 =item * C<ul> – underlined text
 
 120 =item * C<s> – striked out text
 
 122 =item * C<sub>, C<sup> – subscripted and superscripted text
 
 124 =item * C<ul>, C<ol>, C<li> – unordered lists (converted to an itemized
 
 125 list), ordered lists (converted to enumerated lists) and their list
 
 128 =item * C<p>, C<br> – Paragraph markers and line breaks
 
 132 This function is tailored for working on the input of CKEditor, not on
 
 133 arbitrary HTML content. It works nicely in tandem with the
 
 134 Rose::DB::Object helper functions C<…_as_restricted_html> (see
 
 135 L<SL::DB::Helper::AttrHTML/attr_html>).
 
 137 Attributes are silently removed and ignored. All other markup and the
 
 138 normal text are escaped the same as in L</filter>.
 
 144 Initializes the plugin. Automatically called by Template::Toolkit when
 
 145 the plugin is loaded.
 
 147 =item C<required_packages_for_html>
 
 149 Returns LaTeX code loading packages that are required for the
 
 150 formatting done with L</filter_html>. This function must be called and
 
 151 its output inserted before the C<\begin{document}> line if that
 
 152 function is used within the document.
 
 154 It is not required for normal text escaping with L</filter>.
 
 164 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>