From 69e35d3c515cd30c9baf82468008d0b0643e1e1f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 24 Aug 2008 15:21:51 -0400 Subject: [PATCH] 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. --- IkiWiki/Plugin/teximg.pm | 62 +++++++++++++++---- debian/NEWS | 24 +++++++ debian/changelog | 6 ++ debian/control | 2 +- doc/plugins/teximg.mdwn | 8 +++ ..._teximg_latex_preamble_to_config_file.mdwn | 2 + po/ikiwiki.pot | 21 +++++-- 7 files changed, 109 insertions(+), 16 deletions(-) diff --git a/IkiWiki/Plugin/teximg.pm b/IkiWiki/Plugin/teximg.pm index 369c10882..661d97b1f 100644 --- a/IkiWiki/Plugin/teximg.pm +++ b/IkiWiki/Plugin/teximg.pm @@ -10,6 +10,17 @@ use File::Temp qw(tempdir); use HTML::Entities; use IkiWiki 2.00; +my $default_prefix = < "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 { diff --git a/debian/NEWS b/debian/NEWS index e0c9b77eb..a7a145d9b 100644 --- a/debian/NEWS +++ b/debian/NEWS @@ -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 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. diff --git a/debian/changelog b/debian/changelog index 460ddc27f..5e537a9db 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Thu, 21 Aug 2008 16:20:58 -0400 diff --git a/debian/control b/debian/control index 72aa12ab8..b900052dc 100644 --- a/debian/control +++ b/debian/control @@ -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 diff --git a/doc/plugins/teximg.mdwn b/doc/plugins/teximg.mdwn index 1908cfb79..07ebb6d99 100644 --- a/doc/plugins/teximg.mdwn +++ b/doc/plugins/teximg.mdwn @@ -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`. diff --git a/doc/todo/Move_teximg_latex_preamble_to_config_file.mdwn b/doc/todo/Move_teximg_latex_preamble_to_config_file.mdwn index 2d5415c09..d94d24ee4 100644 --- a/doc/todo/Move_teximg_latex_preamble_to_config_file.mdwn +++ b/doc/todo/Move_teximg_latex_preamble_to_config_file.mdwn @@ -152,3 +152,5 @@ Happy TeXing. return 1; } else { + +[[done]] diff --git a/po/ikiwiki.pot b/po/ikiwiki.pot index 99a18be37..60ee59737 100644 --- a/po/ikiwiki.pot +++ b/po/ikiwiki.pot @@ -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 \n" "Language-Team: LANGUAGE \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" -- 2.32.0.93.g670b81a890