home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Text / Wiki / Render / Latex.php next >
Encoding:
PHP Script  |  2008-07-02  |  2.4 KB  |  90 lines

  1. <?php
  2.  
  3. /**
  4. * Formats parsed Text_Wiki for LaTeX rendering.
  5. * $Id: Latex.php,v 1.2 2004/09/25 19:05:13 pmjones Exp $
  6. * @author Jeremy Cowgar <jeremy@cowgar.com>
  7. * @package Text_Wiki
  8. * @todo [http://google.com] becomes 1 with a LaTeX footnote in subscript.
  9. *       This should be a normal LaTeX footnote associated with the
  10. *       previous word?
  11. * @todo parse "..." to be ``...''
  12. * @todo parse '...' to be `...'
  13. * @todo move escape_latex to a static function, move escaping to the
  14. *       individual .php files they are associated with
  15. * @todo allow the user to add conf items to do things like
  16. *       + A custom document header
  17. *       + Custom page headings
  18. *       + Include packages
  19. *       + Set Title, Author, Date
  20. *       + Include a title page
  21. *       + Not output Document Head/Foot (maybe combinding many pages?)
  22. */
  23.  
  24. class Text_Wiki_Render_Latex extends Text_Wiki_Render {
  25.     function escape_latex ($txt) {
  26.         $txt = str_replace("\\", "\\\\", $txt);
  27.         $txt = str_replace('#', '\#', $txt);
  28.         $txt = str_replace('$', '\$', $txt);
  29.         $txt = str_replace('%', '\%', $txt);
  30.         $txt = str_replace('^', '\^', $txt);
  31.         $txt = str_replace('&', '\&', $txt);
  32.         $txt = str_replace('_', '\_', $txt);
  33.         $txt = str_replace('{', '\{', $txt);
  34.         $txt = str_replace('}', '\}', $txt);
  35.         
  36.         // Typeset things a bit prettier than normas
  37.         $txt = str_replace('~',   '$\sim$', $txt);
  38.         $txt = str_replace('...', '\ldots', $txt);
  39.  
  40.         return $txt;
  41.     }
  42.  
  43.     function escape($tok, $ele) {
  44.         if (isset($tok[$ele])) {
  45.             $tok[$ele] = $this->escape_latex($tok[$ele]);
  46.         }
  47.  
  48.         return $tok;
  49.     }
  50.     
  51.     function pre()
  52.     {
  53.         foreach ($this->wiki->tokens as $k => $tok) {
  54.             if ($tok[0] == 'Code') {
  55.                 continue;
  56.             }
  57.  
  58.             $tok[1] = $this->escape($tok[1], 'text');
  59.             $tok[1] = $this->escape($tok[1], 'page');
  60.             $tok[1] = $this->escape($tok[1], 'href');
  61.             
  62.             $this->wiki->tokens[$k] = $tok;
  63.         }
  64.  
  65.         $this->wiki->source = $this->escape_latex($this->wiki->source);
  66.  
  67.         return
  68.             "\\documentclass{article}\n".
  69.             "\\usepackage{ulem}\n".
  70.             "\\pagestyle{headings}\n".
  71.             "\\begin{document}\n";
  72.     }
  73.     
  74.     function post()
  75.     {
  76.         return "\\end{document}\n";
  77.     }
  78.     
  79. }
  80. ?>