Skip to content

Commit

Permalink
Merge branch 'master' of github.com:davibarreira/PlutoLatexConverter.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
davibarreira committed Jan 9, 2022
2 parents 3ed70d8 + e169c8a commit 4eac80d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1.6.3]
julia-version: [1.6.5, 1.7.1]
julia-arch: [x64, x86]
os: [ubuntu-latest, windows-latest, macOS-latest]
exclude:
Expand Down
6 changes: 3 additions & 3 deletions src/auxiliarytex.jl

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/jupyterconverter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function jupytertolatex(notebook, targetdir="./build_latex"; template=:book, fon
# Checks whether the cell has code and whether the code is hidden
elseif get(cell,"cell_type", nothing) == "code" && nestedget(cell,["metadata","jupyter", "source_hidden"],nothing) === nothing
if get(cell,"outputs", nothing) != []
write(f,"\n\\begin{lstlisting}[language=JuliaLocal, style=julia]\n")
write(f,"\n\\bigskip")
# The textcl=true option is for using words with accent in the comments. Useful for non-english.
write(f,"\n\\begin{lstlisting}[language=JuliaLocal, style=julia, texcl=true]\n")
write(f, strip(join(cell["source"])))
write(f,"\n\\end{lstlisting}\n")
end
Expand All @@ -55,16 +57,22 @@ function jupytertolatex(notebook, targetdir="./build_latex"; template=:book, fon
if get(cell, "cell_type", nothing) == "code" && !check_output_hidden
for output in get(cell, "outputs", nothing)
if get(output, "output_type", nothing) == "stream"
write(f,"\n\\begingroup\n")
write(f,"\n\\fontsize{10pt}{12pt}\\selectfont\n")
write(f,"\n\\begin{verbatim}\n")
write(f, join(output["text"]))
write(f,"\n\\end{verbatim}\n")
write(f,"\n\\endgroup\n")
elseif get(output, "output_type", nothing) == "execute_result"
if nestedget(output,["data","text/latex"], nothing) !== nothing
write(f, "\n"*join(output["data"]["text/latex"]))
elseif nestedget(output,["data","text/plain"], nothing) !== nothing
write(f,"\n\\begingroup\n")
write(f,"\n\\fontsize{10pt}{12pt}\\selectfont\n")
write(f,"\n\\begin{verbatim}\n")
write(f, "\n"*join(output["data"]["text/plain"]))
write(f,"\n\\end{verbatim}\n")
write(f,"\n\\endgroup\n")
end
if nestedget(output,["data","image/png"], nothing) !== nothing
png = base64decode(output["data"]["image/png"])
Expand Down
3 changes: 3 additions & 0 deletions src/markdowntolatex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ function markdowntolatex(md, targetdir, notebookdir; template=:book)
parsedtext = ""
for line in split(md, "\n")
l = strip(line)
if l == ""
l = "\n\n"
end

if startswith(l, "```math")
tag = !tag
Expand Down
12 changes: 6 additions & 6 deletions src/templates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ imports some more packages specific for mathematics.
function createtemplate(path=".", template=:book)

if template == :book
tex = "%! TeX program = lualatex\n\\documentclass[12pt, oneside]{book}\n\n\\usepackage{listings}\n\n\\pagestyle{plain}\n\\usepackage{pdfpages}\n\\usepackage{titlesec}\n\n\\usepackage[square,numbers]{natbib}\n\\usepackage[pdftex,bookmarks=true,bookmarksopen=false,bookmarksnumbered=true,colorlinks=true,linkcolor=blue]{hyperref}\n\\usepackage[utf8]{inputenc}\n\\usepackage{float}\n\\usepackage{enumerate}\n\n%%%%%%% JULIA %%%%%%%%%%\n\\input{julia_font}\n\\input{julia_listings}\n\\input{julia_listings}\n\\input{julia_listings_unicode}\n\n\\lstdefinelanguage{JuliaLocal}{\n language = Julia, % inherit Julia lang. to add keywords\n morekeywords = [3]{thompson_sampling}, % define more functions\n morekeywords = [2]{Beta, Distributions}, % define more types and modules\n}\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n%%%%%%%%%% BOOK INFORMATION %%%%%%%%%%\n\\newcommand{\\authorname}{Name}\n\\newcommand{\\booktitle}{Title}\n\\newcommand{\\subtitle}{Subtitle}\n\\newcommand{\\publisher}{TBD}\n\\newcommand{\\editionyear}{2021}\n\\newcommand{\\isbn}{XYZ} % replace this with your own ISBN\n\n\\title{\\booktitle}\n\\author{\\authorname}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\begin{document}\n\n% \\includepdf{cover.pdf}\n\n\\frontmatter\n\\input{frontmatter/titlepage}\n\\input{frontmatter/copyright}\n% \\include{preface}\n\n\\newpage\n\\tableofcontents\n\n\\mainmatter\n\\newpage\n% INCLUDE NOTEBOOKS HERE %\n\n\\bibliography{ref}\n\n\\bibliographystyle{plainnat}\n\n\\include{appendix}\n\n\\end{document}\n"
tex = read(String(@__DIR__)*"/../templates/book.tex", String)

elseif template == :mathbook
tex = "%! TeX program = lualatex\n\\documentclass[12pt, oneside]{book}\n\n\\usepackage{listings}\n\n\\pagestyle{plain}\n\\usepackage{pdfpages}\n\\usepackage{titlesec}\n\n%%%% MATH PACKAGES %%%%\n\n\\usepackage{amsfonts, amsthm,amsmath,amssymb,mathtools}\n\\usepackage{bbm}\n\\usepackage{bm}\n\\usepackage{mathtools}\n\\usepackage{thmtools} % List of Theorems\n\n%%%%%%%%%%%%%%%%%%%%%%%\n\n\\usepackage[square,numbers]{natbib}\n\\usepackage[pdftex,bookmarks=true,bookmarksopen=false,bookmarksnumbered=true,colorlinks=true,linkcolor=blue]{hyperref}\n\\usepackage[utf8]{inputenc}\n\\usepackage{float}\n\\usepackage{enumerate}\n\n%%%%%%% JULIA %%%%%%%%%%\n\\input{julia_font}\n\\input{julia_listings}\n\\input{julia_listings_unicode}\n\n\\lstdefinelanguage{JuliaLocal}{\n language = Julia, % inherit Julia lang. to add keywords\n morekeywords = [3]{thompson_sampling}, % define more functions\n morekeywords = [2]{Beta, Distributions}, % define more types and modules\n}\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n%%%%%%%%%% BOOK INFORMATION %%%%%%%%%%\n\\newcommand{\\authorname}{Name}\n\\newcommand{\\booktitle}{Title}\n\\newcommand{\\subtitle}{Subtitle}\n\\newcommand{\\publisher}{TBD}\n\\newcommand{\\editionyear}{2021}\n\\newcommand{\\isbn}{XYZ} % replace this with your own ISBN\n\n\\title{\\booktitle}\n\\author{\\authorname}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%% MATH STYLE %%%%%%%%%%%%%\n\\newtheoremstyle{bfnote}%\n {}{}\n {}{}\n {\\bfseries}{.}\n { }{\\thmname{#1}\\thmnumber{ #2}\\thmnote{ (#3)}}\n\\theoremstyle{bfnote}\n\\newenvironment{prf}[1][Proof]{\\textbf{#1.} }{\\qed}\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{definition}[theorem]{Definition}\n\\newtheorem{exer}{Exercise}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newtheorem{proposition}[theorem]{Proposition}\n\n\\newtheorem{note}{Note}[section]\n\\newtheorem{example}{Example}[section]\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{document}\n\n% \\includepdf{cover.pdf}\n\n\\frontmatter\n\\input{frontmatter/titlepage}\n\\input{frontmatter/copyright}\n% \\include{preface}\n\n\\newpage\n\\tableofcontents\n\n%\\listoftheorems[onlynamed]\n\n\\mainmatter\n\\newpage\n% INCLUDE NOTEBOOKS HERE %\n\n\\bibliography{ref}\n\n\\bibliographystyle{plainnat}\n\n\\include{appendix}\n\n\\end{document}\n\n"
tex = read(String(@__DIR__)*"/../templates/mathbook.tex", String)


elseif template == :article
tex = "%! TeX program = lualatex\n\\documentclass[12pt]{article}\n\n\\usepackage{listings}\n\n\\pagestyle{plain}\n\\usepackage{pdfpages}\n\n\\usepackage[square,numbers]{natbib}\n\\usepackage[pdftex,bookmarks=true,bookmarksopen=false,bookmarksnumbered=true,colorlinks=true,linkcolor=blue]{hyperref}\n\\usepackage[utf8]{inputenc}\n\\usepackage{float}\n\\usepackage{enumerate}\n\n%%%%%%% JULIA %%%%%%%%%%\n\\input{julia_font}\n\\input{julia_listings}\n\\input{julia_listings}\n\\input{julia_listings_unicode}\n\n\\lstdefinelanguage{JuliaLocal}{\n language = Julia, % inherit Julia lang. to add keywords\n}\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\begin{document}\n\n\\newpage\n% INCLUDE NOTEBOOKS HERE %\n\n\n\\bibliography{ref}\n\n\\bibliographystyle{plainnat}\n\n\\include{appendix}\n\n\\end{document}\n"
tex = read(String(@__DIR__)*"/../templates/article.tex", String)

elseif template == :matharticle
tex = "%! TeX program = lualatex\n\\documentclass[12pt]{article}\n\n\\usepackage{listings}\n\n\\pagestyle{plain}\n\\usepackage{pdfpages}\n\n\\usepackage[square,numbers]{natbib}\n\\usepackage[pdftex,bookmarks=true,bookmarksopen=false,bookmarksnumbered=true,colorlinks=true,linkcolor=blue]{hyperref}\n\\usepackage[utf8]{inputenc}\n\\usepackage{float}\n\\usepackage{enumerate}\n\n%%%% MATH PACKAGES %%%%\n\n\\usepackage{amsfonts, amsthm,amsmath,amssymb,mathtools}\n\\usepackage{bbm}\n\\usepackage{bm}\n\\usepackage{mathtools}\n\\usepackage{thmtools} % List of Theorems\n\n%%%%%%% JULIA %%%%%%%%%%\n\\input{julia_font}\n\\input{julia_listings}\n\\input{julia_listings}\n\\input{julia_listings_unicode}\n\n\\lstdefinelanguage{JuliaLocal}{\n language = Julia, % inherit Julia lang. to add keywords\n}\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%% MATH STYLE %%%%%%%%%%%%%\n\\newtheoremstyle{bfnote}%\n {}{}\n {}{}\n {\\bfseries}{.}\n { }{\\thmname{#1}\\thmnumber{ #2}\\thmnote{ (#3)}}\n\\theoremstyle{bfnote}\n\\newenvironment{prf}[1][Proof]{\\textbf{#1.} }{\\qed}\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{definition}[theorem]{Definition}\n\\newtheorem{exer}{Exercise}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newtheorem{proposition}[theorem]{Proposition}\n\n\\newtheorem{note}{Note}[section]\n\\newtheorem{example}{Example}[section]\n\n\n\\begin{document}\n\n\\newpage\n% INCLUDE NOTEBOOKS HERE %\n\n\n\\bibliography{ref}\n\n\\bibliographystyle{plainnat}\n\n\\include{appendix}\n\n\\end{document}\n"
tex = read(String(@__DIR__)*"/../templates/matharticle.tex", String)
end

maintex = path * "/main.tex"
Expand All @@ -41,7 +41,7 @@ function createtemplate(path=".", template=:book)
end
end

titlepage = "% \\pagestyle{empty}\n\n% % Half title page\n% {\n% \\centering\n\n% ~\n\n% \\vspace{24pt}\n% {\\scshape\\Huge \\booktitle \\par}\n% }\n% \\cleardoublepage\n\n% Title page\n\\begin{titlepage}\n\t\\centering\n\n\t~\n\n\t\\vspace{24pt}\n\t{\\scshape\\Huge \\booktitle\\par}\n\t\\vspace{6pt}\n\t{\\scshape\\large \\subtitle\\par}\n\t\\vspace{\\stretch{1.25}}\n\t{\\itshape\\large by\\par}\n\t\\vspace{6pt}\n\t{\\itshape\\Large \\authorname\\par}\n\t\\vspace{\\stretch{6}}\n\t{\\large \\publisher\\par}\n\\end{titlepage}\n"
titlepage = read("../templates/frontmatter/titlepage.tex", String)

titlepagetex = path * "/frontmatter/titlepage.tex"
if !isfile(titlepagetex)
Expand All @@ -50,7 +50,7 @@ function createtemplate(path=".", template=:book)
end
end

copyright = "% Copyright page\n\n{\\small\n\\setlength{\\parindent}{0em}\\setlength{\\parskip}{1em}\n\n~\n\n\\vfill\n\nCopyright \\copyright{} 2021 \\authorname\n\nAll rights reserved. No part of this publication may be reproduced, stored or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise without written permission from the publisher. It is illegal to copy this book, post it to a website, or distribute it by any other means without permission.\n\nFirst edition, \\editionyear{}\n\nISBN \\isbn{} % see main.tex\n\nPublished by \\publisher{}\n}\n"
copyright = read("../templates/frontmatter/copyright.tex", String)

copyrighttex = path * "/frontmatter/copyright.tex"
if !isfile(copyrighttex)
Expand Down
5 changes: 5 additions & 0 deletions templates/article.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
%! TeX program = lualatex
\documentclass[12pt]{article}

\usepackage[margin=3cm]{geometry}
\parindent 0in
\parskip 12pt
\geometry{margin=1in, headsep=0.25in}

\usepackage{listings}

\pagestyle{plain}
Expand Down
5 changes: 5 additions & 0 deletions templates/book.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
%! TeX program = lualatex
\documentclass[12pt, oneside]{book}

\usepackage[margin=3cm]{geometry}
\parindent 0in
\parskip 12pt
\geometry{margin=1in, headsep=0.25in}

\usepackage{listings}
\usepackage{hyperref}

Expand Down
5 changes: 5 additions & 0 deletions templates/matharticle.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
%! TeX program = lualatex
\documentclass[12pt]{article}

\usepackage[margin=3cm]{geometry}
\parindent 0in
\parskip 12pt
\geometry{margin=1in, headsep=0.25in}

\usepackage{listings}

\pagestyle{plain}
Expand Down
5 changes: 5 additions & 0 deletions templates/mathbook.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
%! TeX program = lualatex
\documentclass[12pt, oneside]{book}

\usepackage[margin=3cm]{geometry}
\parindent 0in
\parskip 12pt
\geometry{margin=1in, headsep=0.25in}

\usepackage{listings}

\pagestyle{plain}
Expand Down
6 changes: 5 additions & 1 deletion test/jupyter/jupyternotebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@
"another **bold** and *more italics* and\n",
"[another](https://github.com/). Ends with two figures\n",
"![Figure](figure.svg) and\n",
"![Figure 2](figure.svg) again."
"![Figure 2](figure.svg) again.\n",
"\n",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n",
"\n",
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
]
},
{
Expand Down

0 comments on commit 4eac80d

Please sign in to comment.