Extension:WikiTex/Documentation

WikiTex Documentation

Usage
Use &lt;wikitex&gt; and &lt;/wikitex&gt; to enclose that part of the page (maybe all page) where you want to use the usual math editing: &lt;wikitex&gt; Let $Q$ be any finite set, and $\mathcal B=2^Q$ be the collection of the subsets of $Q$. Let $f:\mathcal B\rightarrow \mathbb R$ be a function assigning real numbers to the subsets of $Q$ and suppose $f$ satisfies the following conditions: :(i) $f(A)\ge 0$ for all $A\subseteq Q$, $f(\emptyset)=0$, :(ii) $f$ is monotone, i.e. if $A\subseteq B\subseteq Q$ then $f(A)\le f(B)$, :(iii) $f$ is submodular, i.e. if $A$ and $B$ are different subsets of $Q$ then $$ \eqno{(2)} f(A)+f(B)\ge f(A\cap B) + f(A\cup B). $$ &lt;/wikitex&gt; Beware: formulas are typeset with plain TeX with some predefined commands (such as \mathcal or \mathbb above). LaTeX constructs do not work.

The result is

Formula numbers
Displayed formulas might be numbered. Formula numbers are defined within the $$ signs as the argument enclosed inside curly brackets of the \eqno macro: $$\eqno{(*)} a^2 + b^2 = c^2 $$ The formula number is extracted from the formula, and is used directly. This means that no TeX construct can (or should) be used: \eqno{(***)} is prefectly valid. Sorry, no automatic formula numbering and labels. The \eqno macro should be defined in the TexInclude preamble to stop TeX from complaining about \eqno: \def\eqno#1{}

Attributes
The &lt;wikitex&gt; tag accepts a few attributes which are in effect for all formulas until the closing &lt;/wikitex&gt; tag. Attributes come after the wikitex word but before the &gt; sign. Attributes might have a value, then the attribute is followed by an equality sign =, and then the attribute value enclosed within quotation marks: &lt; wikitex refresh dpi="144" &gt; Do not leave spaces around the = sign.

Warning: attribute setting is not part of the formula. It means that if same formula occurs in several &lt;wikitex&gt; blocks with different attribute settings, it will be shown everwhere the way it was generated last time, and not as the particular attribute setting would require.


 * refresh
 * This attribute forces all formulas generated freshly. Formulas are hashed and images are stored by their hash. When the a formula is encountered it is checked first whether the image is there, and it is processed only if no image found. With this attribute all formulas are processed independently whether the image exists or not. Use it when you change the include file, or you want to regenerate the images for some reason.
 * The refresh attribute slows down page rendering significantly. Use it only with the preview feature, and delete it before saving the page.
 * This attribute has effect only when editing the page, but has no effect when vieweing it.
 * You might need to clear your browser's cache before you see the newly generated pictures.


 * dpi="resolution"
 * You can specify the resolution of the picture generated. TeX works with 10 point size symbols and with dpi="100" you will get a picture with true 10 point size. The default value is dpi="120" which gives acceptable results for the typical browser setting.
 * To change the default dpi value, please change it in WikiTex.php. Locate this line, and replace 120 with your favourite number:
 * This is the effect of using different dpi values: [[Image:WikiTexFontSize.png]]
 * This is the effect of using different dpi values: [[Image:WikiTexFontSize.png]]


 * include=" Include:File "
 * You can specify your own TeX macros which will be prepended to all formulas between &lt;wikitex&gt; and &lt;/wikitex&gt;. The value is the wiki page name which contains the macros. You can specify several include files, separated by semicolons:
 * include="Math:TexInclude; Lectures:TexInclude"
 * In this case the content of Math:TexInclude will be included the first, followed by the content of Lectures:TexInclude (which can, for example, redefine previously defined commands).
 * See for a description how to prepare the include files.


 * noinclude
 * without this attribute, the standard include file MediaWiki:TexInclude will be prepended first to the formula. If this attribute is present, this file will not be prepended.
 * Use it only if you know what you are doing. You should define the \eqno macro to ignore its argument, otherwise formula numbering won't work.

CSS for displayed formulas
Displayed formulas, i.e. those between $$ and $$ signs, are formatted differently than inline formulas. First, the text of the display formula is scanned for the \eqno{...} macro, and the text between the curly brackets is extracted as the formula number. Next the formula is typeset, and the picture is placed between &lt;div&gt; and &lt;/div&gt; as follows: &lt;div class="texdisplay"&gt; &lt;span class="dispno"&gt; extracted formula number &lt;/span&gt; &lt;img class="tex" src="..." alt="..." /&gt; &lt;/div&gt; The second line is there only if there formula contains formula number. How this is rendered depens on the definition of the classes "texdisplay", "dispno", and "tex" which should be defined in the actual skin.

The easiest way to make sure that all these classes are defined is to edit the MediaWiki:Common.css file, as described in the Installation section.

Computing vertical adjustment
TeX, as all typesetting programs, keeps track of the base line of each block, and aligns neightbouring blocks vertically along their baselines. To align a formula with the neighbouring text one should know where the baseline of the formula is.

Formulas can grow upwards and downwards quite a lot (think of fractions with fractions in the enumenator or in the denumenator only). When a picture is generated from the formula, it is trimmed to the visible parts, and the place of the base line is lost. The best practice is to assume that it is somewhere at the middle of the picture. Which sometimes gives devastating result. The question is can we recover the position of the baseline?

The appropach taken by Extension:WikiTex is to let TeX tell us this information. The typeset formula is enclosed into a box, and TeX can print out its dimensions, meaning width, height and depth. The last two are measured from the baseline of the box. WikiTex generates the following TeX file: .. preamble copied from the include files \setbox0\hbox{$ here comes the formula itself $}% \message{//\the\dp0//}% \box0% \bye The % marks at the end of the lines prevent generating superfluous empty spaces. The \setbox0\hbox{..} line typesets its argument at stores it in box numbered 0 (used for temporary purposes by TeX). The \message command prints out its argument to the log file. The argument is the depth of box zero surrounded by double slash chartacters. The \box0 command unpacks the content of box zero – and the formula appears here. The last line is the closing command for plain TeX.

The external worker program calls TeX which places this info in the log file. The log file is searched for the text "//depth:&lt;number&gt;pt//", and if found, the "number" is extracted: # search for //depth: in the log file, digits, point, and the - sign allowed DEPTH=`grep "//depth:[0-9.\-]*pt//" this.log 2>/dev/null` # cut the beginning DEPTH=${DEPTH#*depth:} # cut the end DEPTH=${DEPTH%%pt*} Now $DEPTH is the depth of the generated formula in points, which might be a negative number (if the bottom of the formula is above the base line). This value is returned by the worker program. What we have to do is to convert points to pixels, and we've got the position of the base line!

Well, not exactly. TeX works with frames, and not with pixel images. A frame is a rectangle which is a placeholder for the pixel image of the final character. Sometimes a character has pixels outside the frame, sometimes it does not fill the frame from side to side, thus this computation migh displace the baseline a little. Still it is a good approximation, and works quite well.

The &lt;tex&gt; tag
WikiTex internally strips the dollar signs and wraps all formulas between &lt;tex&gt; and &lt;/tex&gt; then calls the rendering routine recursively. You can also use the &lt;tex&gt; tag directly. There are certain differences, which make the two tags behave differently. So be warned.
 * the whole text in a &lt;tex&gt; block is typeset in math mode, thus do not use $ signs at the beginning and at the end.
 * &lt;wikitex&gt; works on block level, while &lt;tex&gt; works on element level. This means, for example, that if you put two &lt;wikitex&gt; blocks next to each other, the second one will start a new paragraph. Putting two &lt;tex&gt; blocks next to each other will produce two adjacent pictures on the same line.
 * Attributes of &lt;wikitex&gt; are in effect for all formulas between $..$ and $$..$$, however have no effect on &lt;tex&gt; blocks. Each &lt;tex&gt; has its own attributes.
 * You can use $ signs inside a &lt;tex&gt; block, but you cannot use in a formula between $..$. Thus &lt;tex&gt; -1 \hbox{ if $x<0$} &lt;/tex&gt; is perfectly valid, while putting this between $..$ you'll get error messages.
 * &lt;tex&gt; has an additional attribute: display. When this attribute is present, the formula is prepended by the TeX command \displaystyle, searched for the command \eqno{...} to extract a formula number, and a display is generated from the picture.