| 1 | |||
| 2 | ######################################################################## | ||
| 3 | # Author: Patrik Lambert (lambert@talp.ucp.es) | ||
| 4 | # Description: Provides methods to write a latex file. | ||
| 5 | # | ||
| 6 | #----------------------------------------------------------------------- | ||
| 7 | # | ||
| 8 | # Copyright 2004 by Patrik Lambert | ||
| 9 | # | ||
| 10 | # This program is free software; you can redistribute it and/or modify | ||
| 11 | # it under the terms of the GNU General Public License as published by | ||
| 12 | # the Free Software Foundation; either version 2 of the License, or | ||
| 13 | # (at your option) any later version. | ||
| 14 | # | ||
| 15 | # This program is distributed in the hope that it will be useful, | ||
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | # GNU General Public License for more details. | ||
| 19 | # | ||
| 20 | # You should have received a copy of the GNU General Public License | ||
| 21 | # along with this program; if not, write to the Free Software | ||
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 23 | ######################################################################## | ||
| 24 | |||
| 25 | package Lingua::Latex; | ||
| 26 | |||
| 27 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 28 | |||
| 29 | 0 | ▶ | sub new { |
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||
| 30 | 0 | my ($pkg) = shift; | |
| 31 | 0 | my $this = {}; | |
| 32 | |||
| 33 | 0 | return bless $this,$pkg; | |
| 34 | } | ||
| 35 | |||
| 36 | 0 | ▶ | sub startFile { |
|
Subroutine
startFile: not called CC=1 SCAR=6.9
| |||
| 37 | 0 | my $this = shift; | |
| 38 | |||
| 39 | 0 | return '\documentclass[10pt]{article} | |
| 40 | \usepackage[dvips]{graphics} | ||
| 41 | \usepackage{amssymb,amsmath} | ||
| 42 | \topmargin 0pt | ||
| 43 | |||
| 44 | \headsep 0pt | ||
| 45 | \evensidemargin 0pt | ||
| 46 | \oddsidemargin \evensidemargin | ||
| 47 | \setlength{\headheight}{0cm} | ||
| 48 | \setlength{\textwidth}{17cm} | ||
| 49 | \setlength{\textheight}{24.5cm} | ||
| 50 | |||
| 51 | \begin{document} | ||
| 52 | |||
| 53 | \newcommand{\ver}[1]{\rotatebox{90}{#1}} | ||
| 54 | |||
| 55 | '; | ||
| 56 | } | ||
| 57 | |||
| 58 | 0 | ▶ | sub endFile { |
|
Subroutine
endFile: not called CC=1 SCAR=6.9
| |||
| 59 | 0 | my $this = shift; | |
| 60 | |||
| 61 | 0 | return ' | |
| 62 | \end{document} | ||
| 63 | '; | ||
| 64 | } | ||
| 65 | |||
| 66 | 0 | ▶ | sub setTabcolsep { |
|
Subroutine
setTabcolsep: not called CC=1 SCAR=6.9
| |||
| 67 | 0 | my ($this,$tabcolsep) = @_; | |
| 68 | 0 | return ' | |
| 69 | \tabcolsep'.$tabcolsep.' | ||
| 70 | '; | ||
| 71 | } | ||
| 72 | |||
| 73 | # fromText: do the conversion from text to latex | ||
| 74 | # INPUT a string in text format | ||
| 75 | # OUTPUT a string in latex-compatible format | ||
| 76 | 0 | ▶ | sub fromText { |
|
Subroutine
fromText: not called CC=1 SCAR=6.9
| |||
| 77 | 0 | my ($this,$txtString) = @_ ; | |
| 78 | 0 | my $line = $txtString; | |
| 79 | |||
| 80 | # Eliminate windows "^M" character | ||
| 81 | 0 | $line =~ s/\ //g; | |
| 82 | |||
| 83 | # Escape special characters | ||
| 84 | 0 | $line =~ s/\\/{\\textbackslash}/g; | |
| 85 | 0 | $line =~ s/{/\\{/g; | |
| 86 | 0 | $line =~ s/}/\\}/g; | |
| 87 | 0 | $line =~ s/\\{\\textbackslash\\}/{\\textbackslash}/g; | |
| 88 | 0 | $line =~ s/\$/\\\$/g; | |
| 89 | 0 | $line =~ s/%/\\%/g; | |
| 90 | 0 | $line =~ s/_/\\_/g; | |
| 91 | 0 | $line =~ s/&/\\&/g; | |
| 92 | 0 | $line =~ s/\#/\\\#/g; | |
| 93 | |||
| 94 | # Ellipses | ||
| 95 | 0 | $line =~ s/(^|[^.])\.\.\.([^.])/\1\\ldots\2/g; | |
| 96 | |||
| 97 | # Fix double quotes | ||
| 98 | 0 | $line =~ s/(^|\s)\"/\1``/g; | |
| 99 | 0 | $line =~ s/\"(\W|$)/''\1/g; | |
| 100 | |||
| 101 | # Fix single quotes | ||
| 102 | 0 | $line =~ s/(^|\s)'/\1`/g; | |
| 103 | |||
| 104 | # Convert return caracters | ||
| 105 | 0 | $line =~ s/\n/\n\n/g; | |
| 106 | # $line =~ s/\n\n/\\\\/g; | ||
| 107 | |||
| 108 | 0 | $line =~ s/\^/\$\\hat\{ \}\$/g; #must be before the s/ê/... | |
| 109 | |||
| 110 | # Escape accents | ||
| 111 | 0 | $line =~ s/à/\\`{a}/gi; | |
| 112 | 0 | $line =~ s/á/\\'{a}/gi; | |
| 113 | 0 | $line =~ s/ä/\\"{a}/gi; | |
| 114 | 0 | $line =~ s/â/\\^{a}/gi; | |
| 115 | |||
| 116 | 0 | $line =~ s/è/\\`{e}/gi; | |
| 117 | 0 | $line =~ s/é/\\'{e}/gi; | |
| 118 | 0 | $line =~ s/ë/\\"{e}/gi; | |
| 119 | 0 | $line =~ s/ê/\\^{e}/gi; | |
| 120 | |||
| 121 | 0 | $line =~ s/ì/\\`{i}/gi; | |
| 122 | 0 | $line =~ s/í/\\'{i}/gi; | |
| 123 | 0 | $line =~ s/ï/\\"{i}/gi; | |
| 124 | 0 | $line =~ s/î/\\^{i}/gi; | |
| 125 | |||
| 126 | 0 | $line =~ s/ò/\\`{o}/gi; | |
| 127 | 0 | $line =~ s/ó/\\'{o}/gi; | |
| 128 | 0 | $line =~ s/ö/\\"{o}/gi; | |
| 129 | 0 | $line =~ s/ô/\\^{o}/gi; | |
| 130 | |||
| 131 | 0 | $line =~ s/ù/\\`{u}/gi; | |
| 132 | 0 | $line =~ s/ú/\\'{u}/gi; | |
| 133 | 0 | $line =~ s/ü/\\"{u}/gi; | |
| 134 | 0 | $line =~ s/û/\\^{u}/gi; | |
| 135 | |||
| 136 | 0 | $line =~ s/ñ/\\~{n}/gi; | |
| 137 | |||
| 138 | # Escape punctuation | ||
| 139 | 0 | $line =~ s/¿/?`/gi; | |
| 140 | 0 | $line =~ s/¡/!`/gi; | |
| 141 | |||
| 142 | # Escape math characters | ||
| 143 | 0 | $line =~ s/([<>]+)/\$$1\$/g; | |
| 144 | |||
| 145 | 0 | return $line; | |
| 146 | |||
| 147 | } | ||
| 148 | |||
| 149 | 0 | ▶ | sub fromTextFile{ |
|
Subroutine
fromTextFile: not called CC=1 SCAR=6.9
| |||
| 150 | 0 | my ($this,$line) = @_; | |
| 151 | 0 | chomp $line; | |
| 152 | 0 | return $this->fromText($line)."\\\\","\n"; | |
| 153 | } | ||
| 154 | |||
| 155 | 1 | 1; | |