Thành viên:Nguyenthephuc/Note: Mathematics Support

Từ VLOS
Bước tới: chuyển hướng, tìm kiếm

MediaWiki uses a program called texvc to render math expressions into nice looking PNG.

Getting it up and running on Windows can be somewhat troublesome, as it was developed on and for linux, so it is recommended to use one of the other options found below. The first alternative solution has the highest success rate, assuming you have the correct software installed.

Note: Maths support is strictly optional. Your wiki will run fine without it, although you'll need it if you want to enter formulae which are more complicated than a simple subscript.

What you'll need for all solutions:

Install these packages to a short directory, preferably one which does not contain spaces. C:\texmf seems to be the most common. You may have to manually add these packages to the path.

Once you have these programs installed, check if the commands gs, latex, dvips and convert (not the built-in windows-tool!) are working by typing them at the cmd prompt. (Note that you may have to use ctrl-c to quit them as they take input from the console if no arguments are supplied). If they're not found you'll have to modify your PATH variable and restart your operating system. (For some reason Apache or PHP doesn't update its PATH until reboot, a service stop-start does not work)

Option A - Using texvc[sửa]

http://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Windows#Building_texvc_on_Windows

Option B - Using LatexRender[sửa]

You may find compiling texvc to be very complicated or simply not working. Here is another solution (Using LatexRender, thanks to Benjamin Zeiss, completed by MetaSharp). The directories given here are examples, use your owns. This method has been successfully tested up to MediaWiki 1.10.0, 1.13.1, 1.15.1 and on MediaWiki 1.15.3.

Installation[sửa]
  1. install the complete MikTeX (not the basic one, use the network installer) in D:\wikitex\miktex
  2. install the static (to be sure dependencies are embed) binary of ImageMagick in D:\wikitex\imagick (ensure there are no spaces in the path you choose)
  3. install AFPL GhostScript in D:\wikitex\ghostscript
  4. copy D:\wikitex\ghostscript\gs8.54\bin\gswin32c.exe to D:\wikitex\ghostscript\gs8.54\bin\gs.exe
    (8.54 can be different depending on version you install)
  5. add to the windows PATH environnement variable this path: D:\wikitex\ghostscript\gs8.54\bin
    (again, 8.54 can be different depending on version you install)
  6. If you installed MiKTeX for all users and are running IIS, you may also need to create MiKTeX folders under "C:\Documents and Settings\Default User\Application Data" and "C:\Documents and Settings\Default User\Local Settings\Application Data". Make sure the IIS working process account running PHP (IUSR_[whoever]) has both read and write permissions to these directories!
  7. open a command line (start -> execute -> cmd.exe)
  8. verify that the following commands are working:
latex
dvips
convert (not the microsoft convert)
gs
Settings[sửa]

(your wiki directory = $)

  • replace the file $/includes/Math.php with this one
  • uncomment or insert in $/LocalSettings.php:
$wgUseTeX= true;
  • insert in $/LocalSettings.php:
#ImageMagick
$wgImageMagickConvertCommand    = 'D:\wikitex\imagick\convert.exe';
$wgImageMagickIdentifyCommand   = 'D:\wikitex\imagick\identify.exe';
#Tex
$wgLaTexCommand                 = 'D:\wikitex\miktex\miktex\bin\latex.exe';
$wgDvipsCommand                 = 'D:\wikitex\miktex\miktex\bin\dvips.exe';
  • reboot if needed so that paths variables are updated for your services too
Verifications[sửa]
  • and voilà ;) Now you can try in the sandbox to see whether it works. Enter something like this and hit preview to see if it works:
<math>\sqrt{2}</math>
  • the folders "math" and "tmp" should have been created in the "images" folder automatically.



Adding support for commutative diagrams[sửa]

To be able to generate commutative diagrams via the LaTeX package xy-pic, just modify the wrap_formula function in your math.php:

  • your function $/includes/Math.php before the change:
   function wrap_formula($latex_formula) {
       $string  = "\documentclass{".$this->_latexclass."}\n";
       $string .= "\usepackage{amsmath}\n";
       $string .= "\usepackage{amsfonts}\n";
       $string .= "\usepackage{amssymb}\n";
       $string .= "\pagestyle{empty}\n";
       $string .= "\begin{document}\n";
       $string .= "$".$latex_formula."$\n";
       $string .= "\end{document}\n";
       return $string;
   }
  • and afterwards:
   function wrap_formula($latex_formula) {
       $string  = "\documentclass{".$this->_latexclass."}\n";
       $string .= "\usepackage{amsmath}\n";
       $string .= "\usepackage{amsfonts}\n";
       $string .= "\usepackage{amssymb}\n";
       $string .= "\pagestyle{empty}\n";
       $string .= "\begin{document}\n";
       $string .= "\input xy\n";
       $string .= "\xyoption{all}\n";
       $string .= "$".$latex_formula."$\n";
       $string .= "\end{document}\n";
       return $string;
   }

Formulas will still work normally as before, as xy-pic is enabled by the \xymatrix{} command. Try this for fun:

<math>\xymatrix{U \ar@/_/[ddr]_y \ar@/^/[drr]^x \ar@{.>}[dr]|-{(x,y)}            \\
 & X \times_Z Y \ar[d]^q \ar[r]_p & X \ar[d]_f       \\
 & Y \ar[r]^g   & Z                }</math>


How to get the latex "picture" package to work[sửa]

Just put something like this into your wiki page:

<math>\setlength{\unitlength}{1cm}
 \begin{picture}(4,2)
 \put(1,1){\circle{3}}
 \put(3,1){\circle*{5}}
 \end{picture}
 </math>
 

Here is the result (modified orders of magnitude!).

Troubleshooting[sửa]

You might experience some problems with formulas not being displayed if you are not logged in. In such a case comment out the 3 following lines in $/LocalSettings.php:

$wgMathPath         = "{$wgUploadPath}/math";
$wgMathDirectory    = "{$wgUploadDirectory}/math";
$wgTmpDirectory     = "{$wgUploadDirectory}/tmp";

like this:

#$wgMathPath         = "{$wgUploadPath}/math";
#$wgMathDirectory    = "{$wgUploadDirectory}/math";
#$wgTmpDirectory     = "{$wgUploadDirectory}/tmp";

or just suppress them. Everything should be working fine now.

You have to give permissions to the webserver to all the folders that need to access. Not just the ones in the wiki image and temporary folders, but also where you installed latex and the other software.

Alternative Solution with dvipng[sửa]

http://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Windows#Alternative_Solution_with_dvipng

Xem thêm[sửa]