]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/latex.mdwn
Merge commit 'upstream/master' into pub/po
[ikiwiki.git] / doc / todo / latex.mdwn
1 How about a plugin adding a
2 [[preprocessor_directive|ikiwiki/directive]] to render some given LaTeX
3 and include it in the page?  This could either render the LaTeX as a PNG via
4 [[!debpkg dvipng]] and include the resulting image in the page, or perhaps
5 render via [HeVeA](http://pauillac.inria.fr/~maranget/hevea/index.html),
6 [TeX2page](http://www.ccs.neu.edu/~dorai/tex2page/tex2page-doc.html), or
7 similar. Useful for mathematics, as well as for stuff like the LaTeX version
8 of the ikiwiki [[/logo]].
9
10 ----
11
12 ikiwiki could also support LaTeX as a document type, again rendering to HTML.
13
14 ----
15
16 Conversely, how about adding a plugin to support exporting to LaTeX?
17
18 >> I did some tests with using Markdown and a customized HTML::Latex and html2latex
19 >> and it appears it will work for me now. (I hope to use ikiwiki for many
20 >> to collaborate on a printed book that will be generated at least once per day in PDF format.)
21 >>
22 >> --JeremyReed
23
24 >>> Have a look at [pandoc](http://code.google.com/p/pandoc/).  It can make PDFs via pdflatex. --[[roktas]]
25
26 >>>> Interesting, just yesterday I was playing with pandoc to make PDFs from my Markdown. Could someone advise me on how to embed these PDFs into ikiwiki? I need some guidance in implementing this. --[[JosephTurian]]
27
28 ----
29
30 [here](http://ng.l4x.org/gitweb/gitweb.cgi?p=ikiwiki.git/.git;a=blob;f=IkiWiki/Plugin/latex.pm) is a first stab at
31 a latex plugin. Examples [here](http://ng.l4x.org/latex/). Currently without image support for hevea. And the latex2html
32 output has the wrong charset and no command line switch to change that. Dreamland.
33
34 As this link is not working, I setted a mirror here: <a href="http://satangoss.sarava.org/ikiwiki/latex.pm">http://satangoss.sarava.org/ikiwiki/latex.pm</a>.
35
36
37 ----
38
39 Okay, now is the time for a mid term report i think.
40
41 The LaTeX Plugin for ikiwiki is now usable, except for the security check. This means at the moment the latex code is not validated, but only added into a very basic latex template. and the image is generated via this path: latex -> dvips -> convert (.tex -> .dvi -> .ps -> .png).
42 The resulting .png is moved into the imagefolder. The name of this image is the md5hash of the code the user wrote into the wiki. So on a second run there is no need to recreate this image, if it exists. This will fasten up all but the first generation of the page. 
43 The generation of the image is done in an temporary folder in /tmp created with tempdir from File::Temp. The tmp-folder name is something like: $md5sumdigest.XXXXXXXX. if there is an .tex file already in this dir it will be overwritten. 
44
45 So until now i finished the basic things, now the most important task is to make an good input validation.
46 This is a bit eased since it is not possible to execute shell commands in perl. Furthermore adding additional packages won't work since the code comes from the user is inserted after \begin{document}. Therefore this will result in an error (and this will stop latex from working --> no image is created).
47
48 So my task for the next weeks is to write an good input validation. 
49 I think this progress is okay, since I'll had to learn the last 5-6 weeks for my final exams in university therefore I can't do anything. From now on I have 3 months of freetime and I'll use them to work heavily on this plugin. 
50 So I think I'm inside my own timetable. :)
51
52 ps: Since I found nothere the possibility to upload an file, here is an link to my page where you can have a look. Comments are very welcome ;-)
53 https://www.der-winnie.de/~winnie/gsoc07/tex.pm
54
55 You'll find an demo site here:
56 https://www.der-winnie.de/wiki/opensource/gsoc2007/
57 I'll add some more complex formulas over the days. But this is basically only pure latex. ;-)
58
59 -- Patrick Winnertz
60
61 > Looks like you're very well on schedule.
62
63 > But I wonder: Do you have any plans to work on the latex to html side of
64 > things too? This page kinda combines both uses of latex; creating gifs
65 > for formulas etc, and creating html. Dreamland already has a latex2html
66 > using plugin submitted above, but it still needs some work, and
67 > particularly, needs the same input validation stuff. And then there's the
68 > idea of using html2latex, to convert an ikiwiki site into a book. Any
69 > plans to work on that too? I guess I'm not sure what the scope is of what
70 > you plan to do as part of GSoC.
71
72 >> Yes I plan to write an html -> tex (or pdf) plugin as well. But I think it is better to work first on the first one and complete it and then work and complete the second one. If it is in the scope of GSoC i don't know, but I'll write it since it is fun to write on an Opensource project ;-)
73
74 >> For latex-> html:
75 >> I have the problem that I don't really see the sense to create html code (this means text or charts) from latex code. But if you like I can also add this variant to create html code. In my eyes it is much more important that it is possible to have complex chemical/physical & math formulas on the website without the need to use extern programs. (and upload the pictures manually).
76
77 >>> Well, I suppose someone might just like latex and want to use it as the
78 >>> markup for their wiki, rather than learning markdown. I guess Midnight
79 >>> wanted it enough to write his plugin. But the use case is not too
80 >>> compelling to me either, honestly. --[[Joey]]
81
82 ### code review
83
84 > The main problem I see with the code is that you seem to unnecessarily create a dummy div tag
85 > in preprocess, and then in format you call create(), which generates an img tag. So, why not 
86 > just create the img tag in preprocess?
87
88 >> Mh okay, I'll improve this. 
89
90 Fixed
91
92 > Another problem: Looks like if latex fails to create the image, the user won't be shown any
93 > of its error message, but just "failed to generate image from code". I suspect that in this 
94 > case being able to see the error message would be important.
95
96 >> Yes, that's true. It would be _very_ hard to provide the user the output of latex since this is really very much. For an simple formula as \frac{1}{2} this could be 2 printed out.
97
98 >>> YM 2 printed pages? Yes, I'm familar with latex's insane errors. :-)
99 >>> However, IMHO, it's worth considering this and doing something. Perhaps
100 >>> put the error inside some kind of box in the html so it's delimited
101 >>> from the rest of the page. (Actually, ikiwiki preprocessor directives in
102 >>> general could mark up their errors better.)
103
104 Okay, I'll provide the log as an link in the wiki. But there should be a kind of mechanism how they can be removed. This could lead to an DOS (create via a bot so much nonsense code that the disk is full.)
105
106 Fixed, the log is now provided if latex will fail.
107
108 > The url handling could stand to be improved. Currently it uses $config{url}, so it depends on that being set. Some ikiwiki builds don't have an url set. The thing to do is to use urlto(), to generate a nice relative url from the page to the image. 
109
110 >> Mh... i choose one single dir explizitly since if you use on several pages the same formula  this would really improve the time to generate the formulas and it would waste extra space if you store every formula 3-4 times. But if you really like I'll change this behaviour. 
111
112 >>> No, that makes sense! (My comments about $config{url} still stand
113 >>> though.
114
115 Yes of course, I'll improve the url handling. My comment was only about the several folder ;-)
116
117 Fixed. Now I use urlto and will_render.
118
119 > Another (minor) problem with the url handling is that you put all the images in a "teximages" directory in the toplevel of the wiki. I think it would be better to put each image in the subdirectory for the page that created it. See how the `img` and `sparkline` plugins handle this.
120
121 > It looks like if the tempdir already exists, tempdir() will croak(), thus crashing ikiwiki. It would be good to catch a failure there and fail more gracefully.
122
123 >> Okay, I'll improve this behaviour. Maybe: if tempdir croak rerun it to get another not existing dir? (But only x times so that this is no endless loop, with x maybe = 3). 
124 >> Then it would not be necessary to inform the user about not generating the image. 
125
126 >>> Or just propigate up an error message. If it's failing, someone is
127 >>> probably trying to DOS ikiwiki or something. :-)
128
129 Fixed. I now use eval { create_tmp } and then:  if ($?) { $returncode = 0 } else { save .tex file ... } ...
130
131
132 > I'm not sure why you're sanitising the PATH before calling latex. This could be problimatic on systems where latex is not in /bin or /usr/bin
133
134 >> Okay what do you suggest to use as PATH? 
135 >> I'll have to change the default settings, since we ikiwiki runs in taint mode. (which is good ;-))
136
137 >>> But, ikiwiki already sanitises path and deletes the IFS and CDPATH etc.
138 >>> See ikiwiki.in.
139
140 Fixed. I'll removed these two lines completly.
141
142 -----
143 Okay here an short timetable how I want to proceed further:
144
145 * Until weekend (21-22. July) I'll try to fix all errors above. (done)
146 * From 22.July until 29. July I'll try to set up a first security check
147   My plans are two parts of a security check:
148     * One with an array of blacklisted regular expression. (This would blacklist all the well known and easy to fetch things like \include {/path/to/something} and things like closing the math formula environment ($$). (done)
149     * the second step will be based on Tom::latex, which will help to parse and get a tree view of the code.
150
151 Okay what do you think of this procedure?
152
153 > --[[Joey]]
154
155 >> -- [[PatrickWinnertz]]
156
157 ----
158
159 > It would be nice if it would output image tags with style="height:1em;" so that the formulas scale
160 > with the rest of the text if you change the font size in your browser (ctrl + +/-).
161
162
163 Thanks for the comment.. is fixed. 
164 Mh... not really fixed :S I added it into the return but it is somehow ignored. I'll figure out why.
165
166 -----
167
168 Okay, the last version of the tex plugin for ikiwiki can be downloaded [here](https://www.der-winnie.de/~winnie/gsoc07/tex.pm). 
169
170 > I've looked this over, fixed the indenting, fixed some variable names
171 > ("$foo" is a bad variable name), removed a gratuotuous use of `tie`,
172 > fixed a bug (the first time it was run, it tried to write the png file
173 > before the teximages/ directory existed) and checked the result in.
174
175 > Can you please flesh out [[plugins/teximg]] with
176 > whatever documentation people who know tex will expect to see?
177
178 Okay, I'll fill this up today I think with information about the plugin
179
180 Done. Is that docu fine with you?
181
182 >> Perhaps add some documentation about the kind of tex code that can be
183 >> used, or a link to some documentation so people who don't know latex
184 >> well can figure this out?
185
186 > Also, please review my changes. In particular, I changed the @badthings
187 > array to use qr//, which is much clearer, but it needs to be tested that
188 > I didn't break the checking code when I did it. It would be nice to write
189 > a test case that tries to feed it bad code and makes sure it rejects it.
190
191 I'll test this now on my server. I'll report here later.
192 Okay, checked. it works fine. My blacklist tests were successfull.
193
194 >
195 > Does it really make sense to have an alt tag for the image
196 > that contains the tex code? Will that make any sense when browsing
197 > without images?
198
199 Mh.. For people who know latex very well this would be enough to imagine how the image would look like. 
200 This are of course the minority of people (but I guess also the minority of people are using non-gui browsers).
201
202
203
204 > I'm thinking about renameing the preprocessor directive to teximg.
205 > \[[!teximg code="" alt="foo"]] makes sense.. Would it make sense to rename
206 > the whole plugin, or do you think that other tex stuff should go in this
207 > same plugin?
208
209 I'll think over this until I'm at work ;) Only for rendering images... not for generating .tex files .../wiki/
210 the name is all the same i think. If you like teximg better than switch :)
211
212
213 > Note: I removed the style= attribute, since as I've told you, the
214 > htmlsanitizer strips those since they can be used to insert javascript. I
215 > put in a class=teximage instead; the style sheet could be modified to
216 > style that, if you want to send a patch for that.
217
218 Ah yes.. sorry forgot to update the plugin in my public_html folder %-). This was my last change in this plugin :) Sorry.
219
220
221
222 > --[[Joey]]
223
224 [[!tag soc]]
225 [[!tag wishlist]]