Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Latex.php

Documentation is available at Latex.php

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

Documentation generated on Mon, 11 Mar 2019 13:56:53 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.