Ignore:
Timestamp:
2004-09-03T16:36:33+12:00 (20 years ago)
Author:
jrm21
Message:
  • guess a title if no \title tag
  • \it tag
  • fractions in maths mode
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/LaTeXPlug.pm

    r8097 r8098  
    2222###########################################################################
    2323
     24# todo:
     25#  \includegraphics
     26#  parse/remove tex \if ... macros
    2427
    2528package LaTeXPlug;
     
    119122    $$textref =~ m@\\title\s*{(.*?)}@s;
    120123    my $title = $1;
     124    if (!$title) {
     125    # no title tag. look for a chapter/section heading
     126    $$textref =~ m@\\(?:chapter|section)\s*{(.*?)}@s; # will get 1st match
     127    $title = $1;
     128    }
     129    if (!$title) {
     130    # no chapter/section heading tags either... use filename
     131    $title = $file;
     132    $title =~ s/\.tex$//i;
     133    $title =~ s/[-_.]/ /g; # turn punctuation into spaces
     134    }
    121135    if ($title) {
    122136    $title =~ s@\\\\@ @g; # embedded newlines
     
    379393    $text =~ s~\\(?:texttt|tt|ttseries)\s*{(.*?)}~<tt>$1</tt>~g;
    380394    $text =~ s~\\emph{(.*?)}~<em>$1</em>~g;
    381     $text =~ s~{\\em\s*(.*?)}~<em>$1</em>~g;
     395    $text =~ s~{\\(?:em|it)\s*(.*?)}~<em>$1</em>~g;
    382396    $text =~ s~{\\(?:bf|bfseries)\s*(.*?)}~<strong>$1</strong>~g;
    383397    $text =~ s~\\(?:textbf|bf|bfseries)\s*{(.*?)}~<strong>$1</strong>~g;
     
    445459    return $verbatim;
    446460}
    447 
     461# only used by process_latex_math
     462# returns a unicode char if applicable, otherwise ascii
     463sub math_fraction {
     464    my $num=$1;
     465    my $denom=$2;
     466
     467    if ($num==1 && $denom==2) {return chr(0xc2).chr(0xbd)}
     468    if ($num==1 && $denom==4) {return chr(0xc2).chr(0xbc)}
     469    if ($num==3 && $denom==4) {return chr(0xc2).chr(0xbe)}
     470    return "$num/$denom";
     471}
    448472
    449473sub process_latex_math {
     
    458482#    $text =~ s~\\cup\b~\xe2\xc8\xaa~g; # union operator - unicode 0x222a
    459483    $text =~ s~\\cup\b~ U ~g;
     484
     485    $text =~ s~\\frac\s*{(.+?)}{(.+?)}~math_fraction($1,$2)~ge;
    460486
    461487    if ($html_markup) {
Note: See TracChangeset for help on using the changeset viewer.