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. * Formats parsed Text_Wiki for LaTeX rendering.
  5. * $Id$
  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.     function escape_latex ($txt{
  25.         $txt str_replace("\\""\\\\"$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.         
  35.         // Typeset things a bit prettier than normas
  36.         $txt str_replace('~',   '$\sim$'$txt);
  37.         $txt str_replace('...''\ldots'$txt);
  38.  
  39.         return $txt;
  40.     }
  41.  
  42.     function escape($tok$ele{
  43.         if (isset($tok[$ele])) {
  44.             $tok[$ele$this->escape_latex($tok[$ele]);
  45.         }
  46.  
  47.         return $tok;
  48.     }
  49.     
  50.     function pre()
  51.     {
  52.         foreach ($this->wiki->tokens as $k => $tok{
  53.             if ($tok[0== 'Code'{
  54.                 continue;
  55.             }
  56.  
  57.             $tok[1$this->escape($tok[1]'text');
  58.             $tok[1$this->escape($tok[1]'page');
  59.             $tok[1$this->escape($tok[1]'href');
  60.             
  61.             $this->wiki->tokens[$k$tok;
  62.         }
  63.  
  64.         $this->wiki->source = $this->escape_latex($this->wiki->source);
  65.  
  66.         return
  67.             "\\documentclass{article}\n".
  68.             "\\usepackage{ulem}\n".
  69.             "\\pagestyle{headings}\n".
  70.             "\\begin{document}\n";
  71.     }
  72.     
  73.     function post()
  74.     {
  75.         return "\\end{document}\n";
  76.     }
  77.     
  78. }
  79. ?>

Documentation generated on Tue, 12 Mar 2019 21:49:19 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.