1 package SL::Template::Plugin::KiviLatex;
4 use parent qw( Template::Plugin::Filter );
11 return $cached_instance ||= $class->SUPER::new(@_);
17 $self->install_filter($self->{ _ARGS }->[0] || 'KiviLatex');
23 my ($self, $text, $args) = @_;
24 return $::locale->quote_special_chars('Template/LaTeX', $text);
29 '<ul>' => "\\begin{itemize} ",
30 '</ul>' => "\\end{itemize} ",
31 '<ol>' => "\\begin{enumerate} ",
32 '</ol>' => "\\end{enumerate} ",
37 '<strong>' => "\\textbf{",
41 '<em>' => "\\textit{",
47 '<sub>' => "\\textsubscript{",
49 '<sup>' => "\\textsuperscript{",
51 '<br/>' => "\\newline ",
52 '<br>' => "\\newline ",
56 my ($self, $text, $args) = @_;
58 $text =~ s{ \r+ }{}gx;
59 $text =~ s{ \n+ }{ }gx;
60 $text =~ s{ (?:\ |\s)+ }{ }gx;
63 if (substr($_, 0, 1) eq '<') {
65 $html_replace{$_} || '';
68 $::locale->quote_special_chars('Template/LaTeX', HTML::Entities::decode_entities($_));
70 } split(m{(<.*?>)}x, $text);
72 return join('', @parts);
75 sub required_packages_for_html {
83 return 'SL::Template::Plugin::KiviLatex';
92 SL::Template::Plugin::KiviLatex - Template::Toolkit plugin for
93 escaping text for use in LaTeX templates
97 From within a LaTeX template. Activate both Template::Toolkit in
98 general and this plugin in particular; must be located before
101 % config: use-template-toolkit=1
102 % config: tag-style=$( )$
105 Later escape some text:
107 $( KiviLatex.format(longdescription) )$
113 =item C<filter $text>
115 Escapes characters in C<$text> with the appropriate LaTeX
116 constructs. Expects normal text without any markup (no HTML, no XML
117 etc). Returns the whole escaped text.
119 =item C<filter_html $html>
121 Converts HTML markup in C<$html> to the appropriate LaTeX
122 constructs. Only the following HTML elements are supported:
126 =item * C<b>, C<strong> – bold text
128 =item * C<it>, C<em> – italic text
130 =item * C<ul> – underlined text
132 =item * C<s> – striked out text
134 =item * C<sub>, C<sup> – subscripted and superscripted text
136 =item * C<ul>, C<ol>, C<li> – unordered lists (converted to an itemized
137 list), ordered lists (converted to enumerated lists) and their list
140 =item * C<p>, C<br> – Paragraph markers and line breaks
144 This function is tailored for working on the input of CKEditor, not on
145 arbitrary HTML content. It works nicely in tandem with the
146 Rose::DB::Object helper functions C<…_as_restricted_html> (see
147 L<SL::DB::Helper::AttrHTML/attr_html>).
149 Attributes are silently removed and ignored. All other markup and the
150 normal text are escaped the same as in L</filter>.
156 Initializes the plugin. Automatically called by Template::Toolkit when
157 the plugin is loaded.
159 =item C<required_packages_for_html>
161 Returns LaTeX code loading packages that are required for the
162 formatting done with L</filter_html>. This function must be called and
163 its output inserted before the C<\begin{document}> line if that
164 function is used within the document.
166 It is not required for normal text escaping with L</filter>.
176 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>