Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 fixes #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/latex_envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from . import latex_envs


__version__ = '1.4.0'
__version__ = '1.4.1'


def _jupyter_nbextension_paths():
Expand Down
27 changes: 26 additions & 1 deletion src/latex_envs/latex_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ class LenvsLatexExporter(LatexExporter):
Exports to a LaTeX document
"""

config_title = Bool(
True, help="Proper Title Format").tag(config=True, alias="ct")
config_biblio = Bool(
True, help="Easy Bibliography Formatting").tag(config=True, alias="cb")
removeHeaders = Bool(
False, help="Remove headers and footers").tag(config=True, alias="rh")
figcaptionProcess = Bool(
Expand Down Expand Up @@ -501,9 +505,26 @@ def tocrefrm(self, text):
newtext = re.sub('\\\\begin{verbatim}[\s]*?<IPython\.core\.display[\S ]*?>[\s]*?\\\\end{verbatim}', '', newtext, flags=re.M) # noqa
# bottom page with links to Index/back/next (suppress this)
# '----[\s]*?<div align=right> [Index](toc.ipynb)[\S ]*?.ipynb\)</div>'
newtext = re.sub('\\\\begin{center}\\\\rule{[\S\s]*?\\\\end{center}[\s]*?\S*\href{toc.ipynb}{Index}[\S\s ]*?.ipynb}{Next}', '', newtext, flags=re.M) # noqa
newtext = re.sub('\\\\begin{center}\\\\rule{[\S\s]*?\\\\end{center}[\s]*?\S*\\\\href{toc.ipynb}{Index}[\S\s ]*?.ipynb}{Next}', '', newtext, flags=re.M) # noqa
return newtext

def configure_title(self, nb_text):
# get rid of the first \maketitle command which is in the wrong place
nb_text = nb_text.replace('\\maketitle', '', 1)
# replace the second (correctly placed) \maketitle command with itself, and make a TOC (table of contents) on the next line
nb_text = nb_text.replace('\\maketitle', '\\maketitle\n\\tableofcontents', 1)
return nb_text

def configure_bibliography(self, nb_text):
# enter your bibliography name here
bibliography_name = "math"
# enter your preferred bibliography style here
bibliography_style = "unsrt"
# construct the string which will insert this information into the document
str = '\n\\bibliographystyle{' + bibliography_style + '}\n\\bibliography{' + bibliography_name +'}'
# replace the current generated text (which causes errors) with the desired text
nb_text = nb_text.replace(r'\hypertarget{references}{%', str)
return nb_text

def postprocess(self, nb_text):
nb_text = nb_text.replace('!nl!', '\n')
Expand All @@ -524,6 +545,10 @@ def postprocess(self, nb_text):
newtext = newtext.replace('\\maketitle', '')
newtext = newtext.replace('\\tableofcontents', '')
nb_text = newtext
if self.config_title:
nb_text = self.configure_title(nb_text)
if self.config_biblio:
nb_text = self.configure_bibliography(nb_text)
if self.tocrefRemove:
nb_text = self.tocrefrm(nb_text)
return nb_text
Expand Down
35 changes: 17 additions & 18 deletions src/latex_envs/templates/thmsInNb_article.tplx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
((* block h5 -*))\subparagraph((* endblock h5 -*))


((* block abstract *))
\tableofcontents
((* endblock abstract *))

%or?
%((* block toc *))\tableofcontents((* endblock toc *))


%===============================================================================
% My custom output style
Expand All @@ -38,19 +31,23 @@
%((*- block output_prompt -*))
%((*- endblock output_prompt -*))


((* block author *))
\author{J.-F. Bercher}
((* endblock author *))

((* block title *))
\title{ }
((* endblock title *))

((* block packages *))
((( super() )))
\usepackage[nottoc,numbib]{tocbibind} % add the bibliography to the TOC
\usepackage{listings} % Used to define pretty listings for code sections [jfb]
\usepackage{float}
\usepackage{amsthm}
\usepackage{amsmath}
\newtheorem{theorem}{Theorem}
\newtheorem{definition}{Definition}
\newtheorem{proposition}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{corollary}{Corollary}
\newtheorem{property}{Property}
\newtheorem{problem}{Promlem}
\newtheorem{exercise}{Exercise}
\newtheorem{example}{Example}
\newtheorem{remark}{Remark}
((* endblock packages *))

%or -- both work
Expand Down Expand Up @@ -147,10 +144,12 @@ framesep=10pt,


((* block bibliography *))
%\bibliographystyle{ieetran}
%\bibliography{Thesis}
% EDIT THE 2 LINES BELOW TO CUSTOMIZE BIBLIOGRAPHY
%\bibliographystyle{unsrt}
%\bibliography{math}
((* endblock bibliography *))


((*- block data_png -*))
((( draw_figure_with_caption(output,'image/png',cell) )))
((*- endblock -*))
Expand Down