# ajtulloch/LaTeX2Markdown

Whitespace

1 parent 25b62b0 commit f5dac03682ea79c4bfc8373911fd0679ee41a1d3 Andrew Tulloch committed Apr 1, 2012
Showing with 53 additions and 48 deletions.
1. +2 −2 config.json
2. +24 −10 converted_latex_sample.md
3. +3 −4 latex2markdown.py
4. +24 −32 latex_sample.tex
4 config.json
 @@ -6,7 +6,7 @@ }, "enumerate": { "line_indent_char": "", - "list_heading": "1.", + "list_heading": "1. ", "markdown_heading": "", "pretty_name": "", "show_count": false @@ -19,7 +19,7 @@ }, "itemize": { "line_indent_char": "", - "list_heading": "*", + "list_heading": "* ", "markdown_heading": "", "pretty_name": "", "show_count": false
34 converted_latex_sample.md
 @@ -1,6 +1,12 @@ -### Example Section +## Usage -#### Theorem 1 (Euclid) + +### Simple Examples + + +This section introduces the usage of the LaTeX2Markdown tool, showing an example of the various environments available. + +#### Theorem 1 (Euclid, 300 BC) > There are infinitely many primes. @@ -25,14 +31,14 @@ To solve this exercise, we first introduce the following lemma. #### Proof -It is easy to show by induction that $-F_m - 2 = F_0 F_1 \dots F_{m-1}. -$ This means that if $d$ divides both $F_n$ and $F_m$ (with $n < m$), then $d$ also divides $F_m - 2$. Hence, $d$ divides 2. But every Fermat number is odd, so $d$ is necessarily one. This proves the lemma. +It is easy to show by induction that +$F_m - 2 = F_0 F_1 \dots F_{m-1}.$ +This means that if $d$ divides both $F_n$ and $F_m$ (with $n < m$), then $d$ also divides $F_m - 2$. Hence, $d$ divides 2. But every Fermat number is odd, so $d$ is necessarily one. This proves the lemma. We can now provide a solution to the exercise. -#### Theorem 2 (Goldbach's proof of the infinitude of primes) +#### Theorem 2 (Goldbach, 1750) > There are infinitely many prime numbers. @@ -42,21 +48,29 @@ We can now provide a solution to the exercise. Choose a prime divisor $p_n$ of each Fermat number $F_n$. By the lemma we know these primes are all distinct, showing there are infinitely many primes. -### LaTeX examples +### Available environments We can format *italic text*, **bold text**, and code blocks. -1. A list item -1. Another list item +1. A numbered list item +1. Another numbered list item + + + + +* A bulleted list item +* Another bulleted list item + #### Theorem 3 -> This is a theorem. It contains an align block. +> This is a theorem. It contains an align block. All math environments supported by MathJaX should work with LaTeX > +> Maxwell's equations, differential form. > \begin{align} > \nabla \cdot \mathbf{E} &= \frac {\rho} {\varepsilon_0} \\\\ > \nabla \cdot \mathbf{B} &= 0 \\\\
7 latex2markdown.py
 @@ -8,7 +8,6 @@ with open("config.json", "r") as f: _block_configuration = json.load(f) - #------------------------------------------------------------------------------ class LaTeX2Markdown(object): @@ -197,7 +196,7 @@ def latex_to_markdown(self): # Throw away content in IGNORE/END block output = re.sub(r"% LaTeX2Markdown IGNORE(.*?)\% LaTeX2Markdown END", "", output, flags=re.DOTALL) - return output + return output.lstrip().rstrip() #------------------------------------------------------------------------------ @@ -208,10 +207,10 @@ def latex_to_markdown(self): output_file = "converted_latex_sample.md" else: input_file, output_file = sys.argv[1], sys.argv[2] - + with open(input_file, 'r') as f: latex_string = f.read() y = LaTeX2Markdown(latex_string) - markdown_string = y.latex_to_markdown().lstrip().rstrip() + markdown_string = y.latex_to_markdown() with open(output_file, 'w') as f_out: f_out.write(markdown_string)
56 latex_sample.tex
 @@ -4,43 +4,28 @@ \usepackage{listings} \onehalfspacing -\usepackage[usenames, dvipsnames]{color} -\definecolor{graphblue}{RGB}{52, 138, 189} -\definecolor{graphpurple}{RGB}{122, 104, 166} - \theoremstyle{plain}% default \newtheorem{thm}{Theorem}[section] \newtheorem{lem}[thm]{Lemma} \newtheorem{prop}[thm]{Proposition} \newtheorem{exer}[thm]{Exercise} -\lstset{ -language=bash, -stepnumber=0, -showspaces=false, -breaklines=true, -basicstyle=\ttfamily\scriptsize, -frame=single, -commentstyle=\scriptsize, -prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}}, -showstringspaces=false, -showtabs=false, -identifierstyle=\ttfamily, -commentstyle=\color{graphpurple}, -keywordstyle=\color{graphblue}, -tabsize=2 -} - -\title{Introduction to LaTeX2Markdown} +\title{LaTeX2Markdown Examples} \author{Andrew Tulloch} \begin{document} % LaTeX2Markdown IGNORE \maketitle % LaTeX2Markdown END -\section{Example Section} -\begin{thm}[Euclid] + +\chapter{Usage} + +\section{Simple Examples} + +This section introduces the usage of the LaTeX2Markdown tool, showing an example of the various environments available. + +\begin{thm}[Euclid, 300 BC] There are infinitely many primes. \end{thm} @@ -60,33 +45,40 @@ \section{Example Section} \end{lem} \begin{proof} - It is easy to show by induction that $- F_m - 2 = F_0 F_1 \dots F_{m-1}. -$ This means that if $d$ divides both $F_n$ and $F_m$ (with $n < m$), then $d$ also divides $F_m - 2$. Hence, $d$ divides 2. But every Fermat number is odd, so $d$ is necessarily one. This proves the lemma. + It is easy to show by induction that + $F_m - 2 = F_0 F_1 \dots F_{m-1}.$ + This means that if $d$ divides both $F_n$ and $F_m$ (with $n < m$), then $d$ also divides $F_m - 2$. Hence, $d$ divides 2. But every Fermat number is odd, so $d$ is necessarily one. This proves the lemma. \end{proof} We can now provide a solution to the exercise. -\begin{thm}[Goldbach's proof of the infinitude of primes] +\begin{thm}[Goldbach, 1750] There are infinitely many prime numbers. \end{thm} \begin{proof} Choose a prime divisor $p_n$ of each Fermat number $F_n$. By the lemma we know these primes are all distinct, showing there are infinitely many primes. \end{proof} -\section{LaTeX examples} +\section{Available environments} We can format \emph{italic text}, \textbf{bold text}, and \texttt{code} blocks. \begin{enumerate} - \item A list item - \item Another list item + \item A numbered list item + \item Another numbered list item \end{enumerate} +\begin{itemize} + \item A bulleted list item + \item Another bulleted list item +\end{itemize} + + \begin{thm} - This is a theorem. It contains an \texttt{align} block. + This is a theorem. It contains an \texttt{align} block. All math environments supported by MathJaX should work with LaTeX + Maxwell's equations, differential form. \begin{align*} \nabla \cdot \mathbf{E} &= \frac {\rho} {\varepsilon_0} \\ \nabla \cdot \mathbf{B} &= 0 \\