# Extension:WikiTex/Documentation

WikiTex Documentation

## Usage

Use <wikitex> and </wikitex> to enclose that part of the page (maybe all page) where you want to use the usual math editing:

<wikitex>
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).$$
</wikitex>


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 <wikitex> tag accepts a few attributes which are in effect for all formulas until the closing </wikitex> tag. Attributes come after the wikitex word but before the > sign. Attributes might have a value, then the attribute is followed by an equality sign =, and then the attribute value enclosed within quotation marks:  < wikitex refresh dpi="144" >  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 <wikitex> 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:  if( !isset(dpi) || ! preg_match('/^[0-9]+/',dpi) ) { dpi=120; }  This is the effect of using different dpi values: include="Include:File" You can specify your own TeX macros which will be prepended to all formulas between <wikitex> and </wikitex>. 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 #TeX include files 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 <div> and </div> as follows:  <div class="texdisplay"> <span class="dispno"> extracted formula number </span> <img class="tex" src="..." alt="..." /> </div>  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. ## TeX include files The included pages are copied into the TeX file verbatim, without any processing. Thus these files should not upset TeX. Also, you want to see and edit them on Wiki. The best way to achieve this is to start all lines with a space. Spaces are (mostly) ingmored by TeX, while wiki understands these lines as something which should be displayed. Nevertheless, wiki might want to process some of your inserted text, such as [[. To prevent this, you can enclose the whole file between <nowiki> and </nowiki>. These words, however, should be protected from TeX. Thus use the TeX comment symbol: %<nowiki> % here are the include macros, each line starting with a space \def\firstmacro{\hbox{first}} \def\secondmacro{\hbox{second}} % and this is the last line of the file: %</nowiki>  ### Macro which you must define To get formula numbers right, you should include this definition in the standard MediaWiki:TexInclude file: \def\eqno#1{}  As all formulas (even displayed ones) are typeset in inline mode, TeX complains about \eqno{} as inappropriate. ### Macro which you might want to define Inline formulas are split at  signs. Thus inside an inline formula you cannot have another  sign. This, however, might be handy if you are typesetting a formula with a text in it. In the formula  \{f: \hbox{f and g are compatible} \}  we are using the \hbox to get the text and the spacing right. Putting  signs before and after this sequence, the result is not a properly formed formula. The remedy is the \math macro:  \def\math#1{#1}  which lets us write the above formula as  \{f: \hbox{\math{f} and \math{g} are compatible} \}  This problem does not occur in displayed formulas. Thus the following TeX formula is fine and handled correctly: $$ f(x) = \cases { -1 & if $x<0$ \cr
0 & if $x=0$ \cr
+1 & otherwise }

## Using Latex

I have chosen plain TeX, rather than LaTeX as the former one is much faster. LaTeX has thousands of features, extensions, which one uses quite rarely. The speed is not so important when you typeset a large chunk of text (such as an article or a book chapter), but becomes important when dozens of small pieces should be processed. Nevertheless, if you think the difference in speed is worth of the gain, hack the code to use latex rather than plain tex. Here are some pointers.

• Prepare the LaTeX file as follows:
 \documentclass{article} % don't set larger size
... insert here all included files
\begin{document} %start of the document
\setbox0\hbox{$...the formula to be typeset comes here...$}