Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/gawk -E
- {
- parsed = $0
- if( $0 ~ /<section .*>/) {
- if( $0 ~ /<section [a-zA-Z ]+>/) {
- parsed = gensub(/<section ([a-zA-Z ]+)>/,"\\\\chapter*{\\1}","g",parsed);
- }
- if( $0 ~ /<section [0-9]+ – .*>/) {
- parsed = gensub(/<section [0-9]+ \– (.*)>/,"\\\\chapter{\\1}","g",parsed);
- }
- if( $0 ~ /<section [0-9]+.[0-9]+ – .*>/) {
- parsed = gensub(/<section [0-9]+.[0-9]+ \– (.*)>/,"\\\\section{\\1}","g",parsed);
- }
- if( $0 ~ /<section [0-9]+.[0-9]+.[0-9]+ – .*>/) {
- parsed = gensub(/<section [0-9]+.[0-9]+.[0-9]+ \– (.*)>/,"\\\\subsection{\\1}","g",parsed);
- }
- }
- # parsed = gensub(/(<code>[^<>]*)\\\\([^<>]*<\/code>)/, "\\1\\\\\\\\\\\\\\2", "g", parsed);
- # parsed = gensub(/(<code>[^<>]*)\\([^<>\\]*<\/code>)/, "\\1\\\\\\\\\\2", "g", parsed);
- # parsed = gensub(/(<code>[^<>]*)\}([^<>]*<\/code>)/, "\\1\\\\}\\2", "g", parsed);
- # parsed = gensub(/(<code>[^<>]*)\{([^<>]*<\/code>)/, "\\1\\\\{\\2", "g", parsed);
- # parsed = gensub(/(<code>[^<>]*)\#([^<>]*<\/code>)/, "\\1\\\\#\\2", "g", parsed);
- parsed = gensub(/<code>([^<>]*)<em>([^<>]*)<\/em>([^<>]*)<\/code>/, "<code>\\1\\2\\3</code>", "g", parsed);
- parsed = gensub(/<code>/, "\\\\lstinline|", "g", parsed);
- parsed = gensub(/<\/code>/, "|", "g", parsed);
- parsed = gensub(/<p>/ , "\\\\par " , "g", parsed);
- parsed = gensub(/<B>/ , "\\\\textbf{" , "g", parsed);
- parsed = gensub(/<\/B>/ , "}" , "g", parsed);
- parsed = gensub(/<b>/ , "\\\\textbf{" , "g", parsed);
- parsed = gensub(/<\/b>/ , "}" , "g", parsed);
- parsed = gensub(/<a [^>]*>/ , "" , "g", parsed);
- parsed = gensub(/<\/a>/ , "" , "g", parsed);
- parsed = gensub(/<table .*>/ , "\\\\begin{table}[H]\\\\centering\\\\begin{tabular}{ccc}", "g", parsed);
- parsed = gensub(/<\/table>/ , "\\\\end{tabular}\\\\end{table}" , "g", parsed);
- parsed = gensub(/<td>/ , "" , "g", parsed);
- parsed = gensub(/<\/td>/ , " \\& " , "g", parsed);
- parsed = gensub(/<tr>/ , "" , "g", parsed);
- parsed = gensub(/<\/tr>/ , "\\\\\\\\" , "g", parsed);
- parsed = gensub(/<ul>/ , "\\\\begin{itemize}" , "g", parsed);
- parsed = gensub(/<\/ul>/ , "\\\\end{itemize}" , "g", parsed);
- parsed = gensub(/<li>/ , "\\\\item " , "g", parsed);
- parsed = gensub(/<font colors?="(\w+)">/, "\\\\textcolor{\\1}{" , "g", parsed);
- parsed = gensub(/<\/font>/ , "}" , "g", parsed);
- parsed = gensub(/<pre>/ , "\\\\begin{lstlisting}" , "g", parsed);
- parsed = gensub(/<\/pre>/ , "\\\\end{lstlisting}" , "g", parsed);
- if( $0 ~ /.*<em>.*<SUB>.*<\/em>.*/) {
- parsed = gensub(/<em>(.*<SUB>.*)<\/em>/,"$ \\1 $","g",parsed);
- parsed = gensub(/<SUB>([^<>]+)<\/SUB>/,"_{\\1}","g",parsed);
- }
- if( $0 ~ /.*<em>[a-zA-Z ]{3,}<\/em>.*/) {
- parsed = gensub(/<em>([\w ]{3,})<\/em>/, "\\\\emph{\\1}", "g", parsed);
- }
- if( $0 ~ /.*<em>[a-zA-Z]{1,2}<\/em>.*/ ) {
- parsed = gensub(/<em>(\w{1,2})<\/em>/,"$ \\1 $","g",parsed);
- }
- if( $0 ~ /.*<em>([^<>]*[0-9=\#\&][^<>]*)<\/em>.*/ ) {
- parsed = gensub(/<em>([^<>]*[0-9=\#\&][^<>]*)<\/em>/,"$ \\1 $","g",parsed);
- }
- parsed = gensub(/<em>/, "\\\\emph{", "g", parsed);
- parsed = gensub(/<\/em>/, "}", "g", parsed);
- parsed = gensub(/\´/, "'", "g", parsed);
- parsed = gensub(/\á/, "á", "g", parsed);
- parsed = gensub(/\é/, "é", "g", parsed);
- parsed = gensub(/\í/, "í", "g", parsed);
- parsed = gensub(/\ç/, "ç", "g", parsed);
- parsed = gensub(/\Ç/, "Ç", "g", parsed);
- parsed = gensub(/\ã/, "ã", "g", parsed);
- parsed = gensub(/\Ã/, "Ã", "g", parsed);
- parsed = gensub(/\ê/, "ê", "g", parsed);
- parsed = gensub(/\</, "<", "g", parsed);
- parsed = gensub(/\&/, "\\\\\\&", "g", parsed);
- parsed = gensub(/\<=/, "\\\\leq", "g", parsed);
- parsed = gensub(/%/, "\\\\%", "g", parsed);
- printf("%s\n",parsed);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement