willu's teximg changes

* teximg: The prefix is configurable, and has changed to not include the
  nonstandard mhchem by default. (willu)
* teximg: dvipng is used if available to render images. Its output is
  antialiased and better than dvips. If not available, the old dvips+convert
  chain will be used. (willu)
* Drop suggests on texlive-science, add suggests on dvipng.
master
Joey Hess 2008-08-24 15:21:51 -04:00
parent 7f5413b0c0
commit 69e35d3c51
7 changed files with 109 additions and 16 deletions

View File

@ -10,6 +10,17 @@ use File::Temp qw(tempdir);
use HTML::Entities;
use IkiWiki 2.00;
my $default_prefix = <<EOPREFIX;
\\documentclass{article}
\\usepackage{amsmath}
\\usepackage{amsfonts}
\\usepackage{amssymb}
\\pagestyle{empty}
\\begin{document}
EOPREFIX
my $default_postfix = '\\end{document}';
sub import { #{{{
hook(type => "getsetup", id => "teximg", call => \&getsetup);
hook(type => "preprocess", id => "teximg", call => \&preprocess);
@ -21,6 +32,26 @@ sub getsetup () { #{{{
safe => 1,
rebuild => undef,
},
teximg_dvipng => {
type => "boolean",
description => "Should teximg use dvipng to render, or dvips and convert?",
safe => 0,
rebuild => undef,
},
teximg_prefix => {
type => "string",
example => $default_prefix,
description => "LaTeX prefix for teximg plugin",
safe => 0, # Not sure how secure LaTeX is...
rebuild => 1,
},
teximg_postfix => {
type => "string",
example => $default_postfix,
description => "LaTeX postfix for teximg plugin",
safe => 0, # Not sure how secure LaTeX is...
rebuild => 1,
},
} #}}}
sub preprocess (@) { #{{{
@ -105,25 +136,34 @@ sub gen_image ($$$$) { #{{{
my $digest = shift;
my $imagedir = shift;
#TODO This should move into the setup file.
my $tex = '\documentclass['.$height.'pt]{scrartcl}';
$tex .= '\usepackage[version=3]{mhchem}';
$tex .= '\usepackage{amsmath}';
$tex .= '\usepackage{amsfonts}';
$tex .= '\usepackage{amssymb}';
$tex .= '\pagestyle{empty}';
$tex .= '\begin{document}';
if (!defined $config{teximg_prefix}) {
$config{teximg_prefix} = $default_prefix;
}
if (!defined $config{teximg_postfix}) {
$config{teximg_postfix} = $default_postfix;
}
if (!defined $config{teximg_dvipng}) {
$config{teximg_dvipng} = length `which dvipng 2>/dev/null`;
}
my $tex = $config{teximg_prefix};
$tex .= '$$'.$code.'$$';
$tex .= '\end{document}';
$tex .= $config{teximg_postfix};
$tex =~ s!\\documentclass{article}!\\documentclass[${height}pt]{article}!g;
$tex =~ s!\\documentclass{scrartcl}!\\documentclass[${height}pt]{scrartcl}!g;
my $tmp = eval { create_tmp_dir($digest) };
if (! $@ &&
writefile("$digest.tex", $tmp, $tex) &&
system("cd $tmp; latex --interaction=nonstopmode $tmp/$digest.tex > /dev/null") == 0 &&
system("dvips -E $tmp/$digest.dvi -o $tmp/$digest.ps 2> $tmp/$digest.log") == 0 &&
# ensure destination directory exists
writefile("$imagedir/$digest.png", $config{destdir}, "") &&
system("convert -density 120 -trim -transparent \"#FFFFFF\" $tmp/$digest.ps $config{destdir}/$imagedir/$digest.png > $tmp/$digest.log") == 0) {
(($config{teximg_dvipng} &&
system("dvipng -D 120 -bg Transparent -T tight -o $config{destdir}/$imagedir/$digest.png $tmp/$digest.dvi > $tmp/$digest.log") == 0
) || (!$config{teximg_dvipng} &&
system("dvips -E $tmp/$digest.dvi -o $tmp/$digest.ps 2> $tmp/$digest.log") == 0 &&
system("convert -density 120 -trim -transparent \"#FFFFFF\" $tmp/$digest.ps $config{destdir}/$imagedir/$digest.png > $tmp/$digest.log") == 0
))) {
return 1;
}
else {

24
debian/NEWS vendored
View File

@ -1,3 +1,27 @@
ikiwiki (2.62) unstable; urgency=low
TexImg standard preamble changed
The teximg plugin now has a configurable LaTeX preamble.
As part of this change the `mchem` LaTeX package has been removed from
the default LaTeX preamble as it wasn't included in many TeX installations.
The previous behaviour can be restored by adding the following to your
ikiwiki setup:
teximg_prefix => '\documentclass{scrartcl}
\usepackage[version=3]{mhchem}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\pagestyle{empty}
\begin{document}',
In addition, the rendering mechanism has been changed to use `dvipng` by
default, if available.
-- Joey Hess <joeyh@debian.org> Sun, 24 Aug 2008 15:00:40 -0400
ikiwiki (2.60) unstable; urgency=low
Admin preferences are moving from the web interface to the setup file.

6
debian/changelog vendored
View File

@ -7,6 +7,12 @@ ikiwiki (2.62) UNRELEASED; urgency=low
* ikiwiki-makerepo: Added support for monotone. (Thomas Keller)
* map: The fix for #449285 was buggy and broke display of parents in certian
circumstances.
* teximg: The prefix is configurable, and has changed to not include the
nonstandard mhchem by default. (willu)
* teximg: dvipng is used if available to render images. Its output is
antialiased and better than dvips. If not available, the old dvips+convert
chain will be used. (willu)
* Drop suggests on texlive-science, add suggests on dvipng.
-- Joey Hess <joeyh@debian.org> Thu, 21 Aug 2008 16:20:58 -0400

2
debian/control vendored
View File

@ -14,7 +14,7 @@ Package: ikiwiki
Architecture: all
Depends: ${perl:Depends}, markdown | libtext-markdown-perl, libhtml-scrubber-perl, libhtml-template-perl, libhtml-parser-perl, liburi-perl
Recommends: gcc | c-compiler, libc6-dev | libc-dev, subversion | git-core (>= 1:1.5.0) | tla | bzr (>= 0.91) | mercurial | monotone (>= 0.38), libxml-simple-perl, libnet-openid-consumer-perl, liblwpx-paranoidagent-perl, libtimedate-perl, libcgi-formbuilder-perl (>= 3.05), libcgi-session-perl (>= 4.14-1), libmail-sendmail-perl, libauthen-passphrase-perl
Suggests: viewvc | gitweb | viewcvs, libsearch-xapian-perl, xapian-omega (>= 1.0.5), librpc-xml-perl, libtext-wikiformat-perl, python, python-docutils, polygen, tidy, libxml-feed-perl, libmailtools-perl, perlmagick, libfile-mimeinfo-perl, libcrypt-ssleay-perl, liblocale-gettext-perl (>= 1.05-1), libtext-typography-perl, libtext-csv-perl, libdigest-sha1-perl, graphviz, libnet-amazon-s3-perl, sparkline-php, texlive, texlive-science
Suggests: viewvc | gitweb | viewcvs, libsearch-xapian-perl, xapian-omega (>= 1.0.5), librpc-xml-perl, libtext-wikiformat-perl, python, python-docutils, polygen, tidy, libxml-feed-perl, libmailtools-perl, perlmagick, libfile-mimeinfo-perl, libcrypt-ssleay-perl, liblocale-gettext-perl (>= 1.05-1), libtext-typography-perl, libtext-csv-perl, libdigest-sha1-perl, graphviz, libnet-amazon-s3-perl, sparkline-php, texlive, dvipng
Conflicts: ikiwiki-plugin-table
Replaces: ikiwiki-plugin-table
Provides: ikiwiki-plugin-table

View File

@ -27,3 +27,11 @@ To add an alt text to the image, use alt="text":
\[[!teximg code="\frac{1}{2}" alt="1/2"]]
See [this site](http://www.der-winnie.de/opensource/gsoc2007) for rendered images.
## configuration
There are several configuration directives that can be used in the setup
file. `teximg_prefix` can be set to change the LaTeX preamble, and
`teximg_postfix` to change the LaTeX postfix. The `teximg_dvipng` setting
can be set to 0 to disable use of `dvipng`, and instead force use of `dvips`
and `convert`.

View File

@ -152,3 +152,5 @@ Happy TeXing.
return 1;
}
else {
[[done]]

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-08-21 22:49-0400\n"
"POT-Creation-Date: 2008-08-24 15:06-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -695,15 +695,15 @@ msgstr ""
msgid "failed to process:"
msgstr ""
#: ../IkiWiki/Plugin/teximg.pm:39
#: ../IkiWiki/Plugin/teximg.pm:70
msgid "missing tex code"
msgstr ""
#: ../IkiWiki/Plugin/teximg.pm:46
#: ../IkiWiki/Plugin/teximg.pm:77
msgid "code includes disallowed latex commands"
msgstr ""
#: ../IkiWiki/Plugin/teximg.pm:97
#: ../IkiWiki/Plugin/teximg.pm:128
msgid "failed to generate image from code"
msgstr ""
@ -800,6 +800,19 @@ msgstr ""
msgid "cannot read %s: %s"
msgstr ""
#: ../IkiWiki/Setup/Automator.pm:33
msgid "you must enter a wikiname (that contains alphanumerics)"
msgstr ""
#: ../IkiWiki/Setup/Automator.pm:67
#, perl-format
msgid "unsupported revision control system %s"
msgstr ""
#: ../IkiWiki/Setup/Automator.pm:83
msgid "failed to set up the repository with ikiwiki-makerepo"
msgstr ""
#: ../IkiWiki/Wrapper.pm:16
#, perl-format
msgid "%s doesn't seem to be executable"