Skip to content

Commit

Permalink
- Now using pdfcrop for cropping built PDF to size; allows for buildi…
Browse files Browse the repository at this point in the history
…ng environments like algorithm or eqnarray

- Added a 'build' folder containing the current build and very rudimentary codes for testing
  • Loading branch information
thomasl86 committed Apr 15, 2017
1 parent b0d661d commit bb7942b
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local.properties

# Project specific
/images/
/latex/
*/latex/*
*.aux
*.log
standalone.tex
Expand Down
139 changes: 127 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# LaTeXbuilder

LaTeXbuilder facilitates the compilation of latex source code into PDF or PNG file format e.g. for the creation of a PNG image file of a math formula.
LaTeXbuilder facilitates the compilation of latex source code into PDF or PNG file format e.g., for the creation of a PNG image file of a math formula.

**Features (to be extended):**

- Builds a PDF or PNG from given LaTeX source code, e.g. a simple formula such as `$e^{i\pi} + 1 = 0$`
- Builds a PDF or PNG from given LaTeX source code, e.g. a simple formula such as `$e^{i\pi} + 1 = 0$` &rarr; <img src="example_images/eq.png" alt="Drawing" style="width: 100px;"/>
- Embeds the LaTeX source code within the created PNG or PDF meaning that the source code is stored within the output files themselves. Allows for convenient re-loading and modification of the output files with LaTeXbuilder.
- Builds figures created with `tikzpicture` and/or `pgfplots`
- (*Experimental*) Parses latex code from within ASCII encoded files that contain other arbitrary characters besides LaTeX source code (e.g., source file written in some other programming language)
- Parses latex code from within ASCII encoded files that contain other arbitrary characters besides LaTeX source code (e.g., source file written in some other programming language)

A command line interface and rudimentary GUI are available.

The program has been tested with *Ubuntu 14.04* and *TeX Live*, and *Windows 7* and *MiKTeX*.
The program has been tested under *Ubuntu 14.04* and *TeX Live*, and *Windows 7* and *MiKTeX*.

**Libraries used:**

Expand All @@ -24,11 +24,12 @@ The program has been tested with *Ubuntu 14.04* and *TeX Live*, and *Windows 7*

For the program to work, the following is necessary:
- A latex distribution that contains a *pdflatex* implementation (e.g. MiKTeX or TeX Live)
- ImageMagick for the conversion from PDF to PNG
- *Windwos OS users only*: The path to `convert.exe` provided by ImageMagick must be given in `config.ini` (e.g. `
- ImageMagick for the conversion from PDF to PNG (using `convert`)
- `pdfcrop`, a pearl script that crops PDFs to size; should come with common LaTeX distributions but pearl interpreter should be installed
- *Windows OS users only*: The path to `convert.exe` provided by ImageMagick must be given in `config.ini` (e.g. `
path = C:\Program Files (x86)\ImageMagick-6.9.0-Q16\`) under section `imagemagick`. Unfortunately, another Windows-specific program called 'convert' shadows ImageMagick's `convert.exe`

## (*Experimental*) Parsing ASCII file & building LaTeX content
## Parsing ASCII file & building LaTeX content
The LaTeX code to be read from within an arbitrary ASCII file must be embedded within the following XML tags:
```xml
<latex>
Expand All @@ -43,8 +44,9 @@ At the current stage, the parser only scans for the above tags.
## Examples

### Building a simple plot created with *tikzpicture*
The command line interface is used to compile sample code consisting of a plot (http://pgfplots.sourceforge.net/gallery.html).
Source file (pgfplots_example.tex):
The command line interface is used to compile sample code consisting of a plot.

**Source file *pgfplots_example.tex* (found [here](http://pgfplots.sourceforge.net/gallery.html)):**
```latex
\begin{tikzpicture}
\begin{axis}[
Expand All @@ -55,10 +57,123 @@ Source file (pgfplots_example.tex):
\end{tikzpicture}
```

Command to build *pgfplots_example.tex*:
**Build command:**

`LaTeXbuilder.jar -b pgfplots_example.tex -o pgfplots_example.png`

Result:
**Result:**

*pgfplots_example.png:*

<img src="example_images/pgfplots_example.png" alt="Drawing" style="width: 450px;"/>

### Parsing Matlab/Octave source file for LaTeX code, extraction & compilation
The command line interface is used to scan the file *bubblesort.m*, extract and compile the LaTeX code contained within the file.

**Source file *bubblesort.m* (found [here](https://www.mathworks.com/matlabcentral/fileexchange/45125-sorting-methods/content/Sorting%20Methods/bubblesort.m)):**

```matlab
%https://www.mathworks.com/matlabcentral/fileexchange/45125-sorting-methods/content/Sorting%20Methods/bubblesort.m
%{
<latex>
<file>bubblesort.png</file>
<code>
%\begin{algorithm}
%\caption{A bubble sort algorithm.}
\begin{algorithmic}
\Function{bubblesort}{$x$}
\State $n \gets length(x)$
\While{$n > 0$}
\State $nnew \gets 0$
\For{$i \gets 1, i < n, i++$}
\If{$x(i) < x(i-1)$}
\State $x \gets swap(x, i, i-1)$
\State $nnew \gets i$
\EndIf
\EndFor
\State $n \gets nnew$
\EndWhile
\State \Return $x$
\EndFunction
\end{algorithmic}
%\end{algorithm}
</code>
</latex>
%}
function x = bubblesort(x)
%--------------------------------------------------------------------------
% Syntax: sx = bubblesort(x);
%
% Inputs: x is a vector of length n
%
% Outputs: sx is the sorted (ascending) version of x
%
% Description: This function sorts the input array x in ascending order
% using the bubble sort algorithm
%
% Complexity: O(n) best-case performance
% O(n^2) average-case performance
% O(n^2) worst-case performance
% O(1) auxiliary space
%
% Author: Brian Moore
% brimoor@umich.edu
%
% Date: January 5, 2014
%--------------------------------------------------------------------------
% Bubble sort
n = length(x);
while (n > 0)
% Iterate through x
nnew = 0;
for i = 2:n
% Swap elements in wrong order
if (x(i) < x(i - 1))
x = swap(x,i,i - 1);
nnew = i;
end
end
n = nnew;
end
end
%{
<latex>
<file>swap.png</file>
<code>
\begin{algorithmic}
\Function{swap}{$x,i,j$}
\State $val \gets x(i)$
\State $x(i) \gets x(j)$
\State $x(j) \gets val$
\State \Return $x$
\EndFunction
\end{algorithmic}
</code>
</latex>
%}
function x = swap(x,i,j)
% Swap x(i) and x(j)
% Note: In practice, x xhould be passed by reference
val = x(i);
x(i) = x(j);
x(j) = val;
end
```
**Build command:**

`LaTeXbuilder.jar --scan bubblesort.m`

**Results:**

For each LaTeX code item encapsulated by the tag `latex`, a separate file is created:

*bubblesort.png*

<img src="./example_images/bubblesort.png" alt="Drawing" style="width: 350px;"/>

*swap.png*

![Result](pgfplots_example.png)
<img src="./example_images/swap.png" alt="Drawing" style="width: 260px;"/>
Binary file modified build/LaTeXbuilder.jar
Binary file not shown.
12 changes: 5 additions & 7 deletions build/config.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[build]
# Absolute path or relative to app dir path to the custom preamble file
latexPreambleFile =
# Creates a border around the built output.
# Can be unit accepted by standalone class
border = 0pt
latexPreambleFile =
# Creates a border around the built output in pt.
border = 3

[imagemagick]
density = 800
quality = 100
# Parameters to provide to imagemagick's 'convert'
params = -background white -alpha remove
# Path to imagemagick (only for Winddows OS)
# Path to imagemagick (only for Windows OS)
# Example: path = C:\Program Files (x86)\ImageMagick-6.9.0-Q16\
path =

path =
Binary file added build/testing/algorithm.pdf
Binary file not shown.
Binary file added build/testing/algorithm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions build/testing/algorithm.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%\begin{algorithm}
% \caption{My algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{MyProcedure}{}
\State $\textit{stringlen} \gets \text{length of }\textit{string}$
\State $i \gets \textit{patlen}$
\BState \emph{top}:
\If {$i > \textit{stringlen}$} \Return false
\EndIf
\State $j \gets \textit{patlen}$
\BState \emph{loop}:
\If {$\textit{string}(i) = \textit{path}(j)$}
\State $j \gets j-1$.
\State $i \gets i-1$.
\State \textbf{goto} \emph{loop}.
\State \textbf{close};
\EndIf
\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
\State \textbf{goto} \emph{top}.
\EndProcedure
\end{algorithmic}
%\end{algorithm}
89 changes: 89 additions & 0 deletions build/testing/bubblesort.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

%https://www.mathworks.com/matlabcentral/fileexchange/45125-sorting-methods/content/Sorting%20Methods/bubblesort.m
%{
<latex>
<file>bubblesort.png</file>
<code>
%\begin{algorithm}
%\caption{A bubble sort algorithm.}
\begin{algorithmic}
\Function{bubblesort}{$x$}
\State $n \gets length(x)$
\While{$n > 0$}
\State $nnew \gets 0$
\For{$i \gets 1, i < n, i++$}
\If{$x(i) < x(i-1)$}
\State $x \gets swap(x, i, i-1)$
\State $nnew \gets i$
\EndIf
\EndFor
\State $n \gets nnew$
\EndWhile
\State \Return $x$
\EndFunction
\end{algorithmic}
%\end{algorithm}
</code>
</latex>
%}
function x = bubblesort(x)
%--------------------------------------------------------------------------
% Syntax: sx = bubblesort(x);
%
% Inputs: x is a vector of length n
%
% Outputs: sx is the sorted (ascending) version of x
%
% Description: This function sorts the input array x in ascending order
% using the bubble sort algorithm
%
% Complexity: O(n) best-case performance
% O(n^2) average-case performance
% O(n^2) worst-case performance
% O(1) auxiliary space
%
% Author: Brian Moore
% brimoor@umich.edu
%
% Date: January 5, 2014
%--------------------------------------------------------------------------
% Bubble sort
n = length(x);
while (n > 0)
% Iterate through x
nnew = 0;
for i = 2:n
% Swap elements in wrong order
if (x(i) < x(i - 1))
x = swap(x,i,i - 1);
nnew = i;
end
end
n = nnew;
end

end
%{
<latex>
<file>swap.png</file>
<code>
\begin{algorithmic}
\Function{swap}{$x,i,j$}
\State $val \gets x(i)$
\State $x(i) \gets x(j)$
\State $x(j) \gets val$
\State \Return $x$
\EndFunction
\end{algorithmic}
</code>
</latex>
%}
function x = swap(x,i,j)
% Swap x(i) and x(j)
% Note: In practice, x xhould be passed by reference

val = x(i);
x(i) = x(j);
x(j) = val;

end
Binary file added build/testing/bubblesort.pdf
Binary file not shown.
Binary file added build/testing/bubblesort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file renamed build/eq.pdf → build/testing/eq.pdf
Binary file not shown.
File renamed without changes
Binary file added build/testing/swap.pdf
Binary file not shown.
Binary file added build/testing/swap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 5 additions & 7 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[build]
# Absolute path or relative to app dir path to the custom preamble file
latexPreambleFile =
# Creates a border around the built output.
# Can be unit accepted by standalone class
border = 0pt
latexPreambleFile =
# Creates a border around the built output in pt.
border = 3

[imagemagick]
density = 800
quality = 100
# Parameters to provide to imagemagick's 'convert'
params = -background white -alpha remove
# Path to imagemagick (only for Winddows OS)
# Path to imagemagick (only for Windows OS)
# Example: path = C:\Program Files (x86)\ImageMagick-6.9.0-Q16\
path =

path =
Binary file added example_images/bubblesort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example_images/eq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added example_images/swap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bb7942b

Please sign in to comment.