From 725d95499f69473c8108c082d59d705f073b3559 Mon Sep 17 00:00:00 2001 From: Evan RR Date: Tue, 26 Nov 2019 22:32:57 -0500 Subject: [PATCH 1/4] Fixed compilatation errors on Python 3.6 and 3.7. Made Changes to the Article Template: 1. Removed Duplicate Title Information. 2. Ensure the TOC follows the Title --- src/latex_envs/latex_envs.py | 13 ++++++++++++- src/latex_envs/templates/thmsInNb_article.tplx | 18 ++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/latex_envs/latex_envs.py b/src/latex_envs/latex_envs.py index 3dbc410..e025643 100644 --- a/src/latex_envs/latex_envs.py +++ b/src/latex_envs/latex_envs.py @@ -414,6 +414,8 @@ class LenvsLatexExporter(LatexExporter): Exports to a LaTeX document """ + config_title = Bool( + True, help="Proper Title Format").tag(config=True, alias="rh") removeHeaders = Bool( False, help="Remove headers and footers").tag(config=True, alias="rh") figcaptionProcess = Bool( @@ -501,9 +503,16 @@ def tocrefrm(self, text): newtext = re.sub('\\\\begin{verbatim}[\s]*?[\s]*?\\\\end{verbatim}', '', newtext, flags=re.M) # noqa # bottom page with links to Index/back/next (suppress this) # '----[\s]*?
[Index](toc.ipynb)[\S ]*?.ipynb\)
' - 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 postprocess(self, nb_text): nb_text = nb_text.replace('!nl!', '\n') @@ -524,6 +533,8 @@ 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.tocrefRemove: nb_text = self.tocrefrm(nb_text) return nb_text diff --git a/src/latex_envs/templates/thmsInNb_article.tplx b/src/latex_envs/templates/thmsInNb_article.tplx index 126f655..4cbd5f6 100644 --- a/src/latex_envs/templates/thmsInNb_article.tplx +++ b/src/latex_envs/templates/thmsInNb_article.tplx @@ -7,13 +7,6 @@ ((* block h5 -*))\subparagraph((* endblock h5 -*)) -((* block abstract *)) -\tableofcontents -((* endblock abstract *)) - -%or? -%((* block toc *))\tableofcontents((* endblock toc *)) - %=============================================================================== % My custom output style @@ -38,19 +31,12 @@ %((*- block output_prompt -*)) %((*- endblock output_prompt -*)) - -((* block author *)) -\author{J.-F. Bercher} -((* endblock author *)) - -((* block title *)) -\title{ } -((* endblock title *)) - ((* block packages *)) ((( super() ))) \usepackage{listings} % Used to define pretty listings for code sections [jfb] \usepackage{float} + \usepackage{amsthm} + \newtheorem{theorem}{Theorem} ((* endblock packages *)) %or -- both work From 09a6cac26d0bf70977e5423bebc084ea1c7246a2 Mon Sep 17 00:00:00 2001 From: Evan RR Date: Tue, 26 Nov 2019 23:44:51 -0500 Subject: [PATCH 2/4] Incremented the Version Number --- src/latex_envs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/latex_envs/__init__.py b/src/latex_envs/__init__.py index 08756b2..8cd7b63 100644 --- a/src/latex_envs/__init__.py +++ b/src/latex_envs/__init__.py @@ -3,7 +3,7 @@ from . import latex_envs -__version__ = '1.4.0' +__version__ = '1.4.1' def _jupyter_nbextension_paths(): From d59c4212a39907802a0f2a60692c559cbb3c70d2 Mon Sep 17 00:00:00 2001 From: Evan RR Date: Wed, 27 Nov 2019 02:25:07 -0500 Subject: [PATCH 3/4] Added a bunch of \newtheorem commands to resolve Environment XXX undefined errors. Now thing should play nice with amsmath package --- src/latex_envs/templates/thmsInNb_article.tplx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/latex_envs/templates/thmsInNb_article.tplx b/src/latex_envs/templates/thmsInNb_article.tplx index 4cbd5f6..f55e1f2 100644 --- a/src/latex_envs/templates/thmsInNb_article.tplx +++ b/src/latex_envs/templates/thmsInNb_article.tplx @@ -36,7 +36,16 @@ \usepackage{listings} % Used to define pretty listings for code sections [jfb] \usepackage{float} \usepackage{amsthm} - \newtheorem{theorem}{Theorem} + \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 From 6c34fe9eaa1a5804078c161c10e38ba37d527b99 Mon Sep 17 00:00:00 2001 From: Evan RR Date: Wed, 27 Nov 2019 06:57:14 -0500 Subject: [PATCH 4/4] Fixed Issue with Refrences not appearing in TOC. Also fixed glitch where the refrences appeard as \hypertarget{possible-improvements}{%, which caused an error as the last { didn't close. Now a user can specify their bibliography name in latex_envs.py. In the future, it would be nice to add a command line switch to specify the bibtex file --- src/latex_envs/latex_envs.py | 16 +++++++++++++++- src/latex_envs/templates/thmsInNb_article.tplx | 8 ++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/latex_envs/latex_envs.py b/src/latex_envs/latex_envs.py index e025643..35180f7 100644 --- a/src/latex_envs/latex_envs.py +++ b/src/latex_envs/latex_envs.py @@ -415,7 +415,9 @@ class LenvsLatexExporter(LatexExporter): """ config_title = Bool( - True, help="Proper Title Format").tag(config=True, alias="rh") + 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( @@ -513,6 +515,16 @@ def configure_title(self, nb_text): 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') @@ -535,6 +547,8 @@ def postprocess(self, nb_text): 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 diff --git a/src/latex_envs/templates/thmsInNb_article.tplx b/src/latex_envs/templates/thmsInNb_article.tplx index f55e1f2..c75927f 100644 --- a/src/latex_envs/templates/thmsInNb_article.tplx +++ b/src/latex_envs/templates/thmsInNb_article.tplx @@ -33,9 +33,11 @@ ((* 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} @@ -142,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 -*))