Merge pull request #271 from jfbercher/3.x

3.x - remove testing/latex_envs
This commit is contained in:
Juergen Hasch
2015-08-31 21:34:05 +02:00
27 changed files with 0 additions and 5672 deletions
Binary file not shown.
@@ -1,129 +0,0 @@
\input{header.tex}
\usepackage{amsthm} % theorems
\usepackage{lettrine}
\usepackage{lastpage}
\usepackage{url}
\usepackage{mdframed}
\usepackage[T1]{fontenc}
%\usepackage[francais]{babel}
\DeclareUnicodeCharacter{00A0}{~} %get rid of "unicode char u8 not set up for use with latex"
\makeatletter
\renewcommand{\@evenfoot}%
{\hfil \upshape Page {\thepage}/\pageref{LastPage}}
\renewcommand{\@oddfoot}{\@evenfoot}
\makeatother
%%% Further colors and hyperref configuration
% Colors
\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webbrown}{rgb}{.6,0,0}
\definecolor{webyellow}{rgb}{0.98,0.92,0.73}
\definecolor{webgray}{rgb}{.753,.753,.753}
\definecolor{webblue}{rgb}{0,0,.8}
\usepackage{hyperref}
\hypersetup{bookmarks,bookmarksnumbered,%bookmarksopen,
colorlinks,linkcolor=webbrown,filecolor=webgreen,citecolor=webgreen,
breaklinks=true,
hyperindex=true
urlcolor=webbrown,pagebackref,pdfpagemode=None,pdfstartview=Fit}
%%%----------------------------------------
%For redefinition of quote env
\usepackage[strict]{changepage}
\usepackage{framed}
%% for a listing environment
\usepackage{verbatim}
\begin{document}
\title{(some) \LaTeX{} environments in Jupyter notebook }
%\begin{abstract}
%Abstract
%\end{abstract}
\maketitle
\thispagestyle{empty} % Removes page numbers
%
\definecolor{lightred}{rgb}{1,0.1,0}
\def\myeqbox#1#2{{\fcolorbox{#1}{light#1}{$\textcolor{#1}{ #2}$}}}
\def\eqbox#1#2#3#4{{\fcolorbox{#1}{#2}{$\textcolor{#3}{ #4}$}}}
% border|background|text
\def\eqboxa#1{{\boxed{#1}}}
\def\eqboxb#1{{\eqbox{green}{white}{green}{#1}}}
\def\eqboxc#1{{\eqbox{blue}{white}{blue}{#1}}}
\def\eqboxd#1{{\eqbox{blue}{lightblue}{blue}{#1}}}
\def\textem#1{\emph{#1}}
\def\url#1{\href{#1}{#1}}
\newtheorem{theorem}{Theorem}
\newtheorem{exercise}{Exercise}
\newtheorem{example}{Example}
\newtheorem{prop}{Property}
\newtheorem{remark}{Remark}
\newtheorem{proposition}{Proposition}
\newtheorem{property}{Property}
\newtheorem{definition}{Definition}
\newtheorem{lemma}{Lemma}
\newtheorem{problem}{Problem}
\newenvironment{textboxa}
{ \begin{mdframed}[backgroundcolor=yellow]}
{ \end{mdframed} }
% -----------------------------------------------------
% The environment for listing is defined here. It is simply derived
% from lstlisting
\definecolor{mylatexlstbkg}{rgb}{0.898,1.0,0.898}
\definecolor{mylatexlstbkg}{rgb}{0.9176,1.0,0.9176}
\lstnewenvironment{listing}
{\lstset{language=[LaTeX]TeX,
backgroundcolor=\color{mylatexlstbkg}}}
{}
%% ----------------------------------------------------
% redefinition environnement quote
% from: http://www.jevon.org/wiki/Fancy_Quotation_Boxes_in_Latex
% for adjustwidth environment
\definecolor{darkblue}{rgb}{0.0, 0.0, 0.55}
\definecolor{formalshade}{rgb}{0.95,0.95,1}
\renewenvironment{quote}{%
\def\FrameCommand{%
\hspace{1pt}%
{\color{darkblue}\vrule width 2pt}%
{\color{formalshade}\vrule width 4pt}%
\colorbox{formalshade}%
}%
\MakeFramed{\advance\hsize-\width\FrameRestore}%
\noindent\hspace{-4.55pt}% disable indenting first paragraph
\begin{adjustwidth}{}{7pt}%
\vspace{2pt}\vspace{2pt}%
}
{%
\vspace{2pt}\end{adjustwidth}\endMakeFramed%
}
%% -------------------
\tableofcontents
%\newpage
\input{latex_env_doc.tex}
\end{document}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

-273
View File
@@ -1,273 +0,0 @@
% Default to the notebook output style
% Inherit from the specified cell style.
\documentclass[11pt]{article}
\usepackage{graphicx} % Used to insert images
\usepackage{adjustbox} % Used to constrain images to a maximum size
\usepackage{color} % Allow colors to be defined
\usepackage{enumerate} % Needed for markdown enumerations to work
\usepackage{geometry} % Used to adjust the document margins
\usepackage{amsmath} % Equations
\usepackage{amssymb} % Equations
\usepackage[mathletters]{ucs} % Extended unicode (utf-8) support
%\usepackage[utf8]{inputenc} % Allow utf-8 characters in the tex document
%\usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document
\usepackage{fancyvrb} % verbatim replacement that allows latex
\usepackage{grffile} % extends the file name processing of package graphics
% to support a larger range
% The hyperref package gives us a pdf with properly built
% internal navigation ('pdf bookmarks' for the table of contents,
% internal cross-reference links, web links for URLs, etc.)
\usepackage{hyperref}
\usepackage{longtable} % longtable support required by pandoc >1.10
\usepackage{booktabs} % table support for pandoc > 1.12.2
\usepackage{listings}
\usepackage{float}
\definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
\definecolor{darkorange}{rgb}{.71,0.21,0.01}
\definecolor{darkgreen}{rgb}{.12,.54,.11}
\definecolor{myteal}{rgb}{.26, .44, .56}
\definecolor{gray}{gray}{0.45}
\definecolor{lightgray}{gray}{.95}
\definecolor{mediumgray}{gray}{.8}
\definecolor{inputbackground}{rgb}{.95, .95, .85}
\definecolor{outputbackground}{rgb}{.95, .95, .95}
\definecolor{traceback}{rgb}{1, .95, .95}
% ansi colors
\definecolor{red}{rgb}{.6,0,0}
\definecolor{green}{rgb}{0,.65,0}
\definecolor{brown}{rgb}{0.6,0.6,0}
\definecolor{blue}{rgb}{0,.145,.698}
\definecolor{purple}{rgb}{.698,.145,.698}
\definecolor{cyan}{rgb}{0,.698,.698}
\definecolor{lightgray}{gray}{0.5}
% bright ansi colors
\definecolor{darkgray}{gray}{0.25}
\definecolor{lightred}{rgb}{1.0,0.39,0.28}
\definecolor{lightgreen}{rgb}{0.48,0.99,0.0}
\definecolor{lightblue}{rgb}{0.53,0.81,0.92}
\definecolor{lightpurple}{rgb}{0.87,0.63,0.87}
\definecolor{lightcyan}{rgb}{0.5,1.0,0.83}
% commands and environments needed by pandoc snippets
% extracted from the output of `pandoc -s`
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}
% Define a nice break command that doesn't care if a line doesn't already
% exist.
\def\br{\hspace*{\fill} \\* }
% Math Jax compatability definitions
\def\gt{>}
\def\lt{<}
% Document parameters
\title{ }
\author{J.-F. Bercher}
% Pygments definitions
\makeatletter
\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax%
\let\PY@ul=\relax \let\PY@tc=\relax%
\let\PY@bc=\relax \let\PY@ff=\relax}
\def\PY@tok#1{\csname PY@tok@#1\endcsname}
\def\PY@toks#1+{\ifx\relax#1\empty\else%
\PY@tok{#1}\expandafter\PY@toks\fi}
\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{%
\PY@it{\PY@bf{\PY@ff{#1}}}}}}}
\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}}
\expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
\expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
\expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}}
\expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit}
\expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
\expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}}
\expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
\expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
\expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}}
\expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}}
\expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
\expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
\expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@err\endcsname{\def\PY@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}
\expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}}
\expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf}
\expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}}
\expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}}
\def\PYZbs{\char`\\}
\def\PYZus{\char`\_}
\def\PYZob{\char`\{}
\def\PYZcb{\char`\}}
\def\PYZca{\char`\^}
\def\PYZam{\char`\&}
\def\PYZlt{\char`\<}
\def\PYZgt{\char`\>}
\def\PYZsh{\char`\#}
\def\PYZpc{\char`\%}
\def\PYZdl{\char`\$}
\def\PYZhy{\char`\-}
\def\PYZsq{\char`\'}
\def\PYZdq{\char`\"}
\def\PYZti{\char`\~}
% for compatibility with earlier versions
\def\PYZat{@}
\def\PYZlb{[}
\def\PYZrb{]}
\makeatother
% Prevent overflowing lines due to hard-to-break entities
\sloppy
% Setup hyperref package
% \hypersetup{
% breaklinks=true, % so long urls are correctly broken across lines
% hidelinks
% }
%%% Further colors and hyperref configuration
% Colors
\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webbrown}{rgb}{.6,0,0}
\definecolor{webyellow}{rgb}{0.98,0.92,0.73}
\definecolor{webgray}{rgb}{.753,.753,.753}
\definecolor{webblue}{rgb}{0,0,.8}
\hypersetup{bookmarks,bookmarksnumbered,%bookmarksopen,
colorlinks,linkcolor=webbrown,filecolor=webgreen,citecolor=webgreen,
breaklinks=true,
hyperindex=true
urlcolor=webbrown,pagebackref,pdfpagemode=None,pdfstartview=Fit}
% Slightly bigger margins than the latex defaults
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
%listings configuration
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
%\usepackage{xcolor}
\definecolor{mylstbkg}{rgb}{1,0.899,0.8}
\lstset{
language=Python,
commentstyle=\color{mygreen},
keywordstyle=\color{blue},
stringstyle=\color{mymauve},
xleftmargin= 1cm,
xrightmargin= 1cm,
showstringspaces=false,
breaklines=true,
texcl=false,
% basicstyle=\ttfamily,
basicstyle=\footnotesize,
frame=none, %was single
%frameround=tttt, %was not%
framesep=10pt,
backgroundcolor=\color{mylstbkg},
%framexleftmargin=10pt,
%framexrightmargin =10pt,
%frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}
inputencoding=utf8,
extendedchars=true,
literate=%
{é}{{\'{e}}}1
{è}{{\`{e}}}1
{ê}{{\^{e}}}1
{ë}{{{e}}}1
{É}{{\'{E}}}1
{Ê}{{\^{E}}}1
{û}{{\^{u}}}1
{ù}{{\`{u}}}1
{à}{{\`{a}}}1
{ç}{{\c{c}}}1
{Ç}{{\c{C}}}1
{î}{{\^{i}}}1
{Î}{{\^{I}}}1
}
%\usepackage{foo}
@@ -1,36 +0,0 @@
#!/usr/bin/env bash
#This is to convert to html the notebooks with embedded LaTex structures
#as used in the latex_envs extension
#required: nodejs, perl
listOfFiles=$*
#from http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
if [ ! -f ./thmsInNb.tpl ]
then
cp -n $SDIR/thmsInNb.tpl . # for conversion, the template file must be in the same directory (or in templates/html dir)
thmsInNbCopied=true
fi
for f in $listOfFiles
do
echo [Translating... $f ]
cp $f temp.ipynb
perl -pi -e s/'\\\\\['/'\$\$'/ temp.ipynb
perl -pi -e s/'\\\\\]'/'\$\$'/ temp.ipynb
ipython3 nbconvert --template=thmsInNb --to html temp --output temp
echo [Post Html processing]
nodejs $SDIR/post_html_thms.js < temp.html > ${f%.ipynb}.html
#echo [Updating links]
#perl -pi -e s/.ipynb/.html/g ${f%.ipynb}.html
echo Done
done
cp -n ~/.ipython/nbextensions/latex_envs.css . # copy the css file in the same directory as the html
if $thmsInNbCopied
then rm thmsInNb.tpl #cleaning
fi
@@ -1,34 +0,0 @@
#!/usr/bin/env bash
# example: ./ipynb_thms_to_latex Lect*.ipynb
listOfFiles=$*
#from http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo $SDIR
cp -n $SDIR/thmsInNb_article.tplx . # for conversion, the template file must be in the same directory (or in templates/html dir)
#cp -n $SDIR/thmsInNb_book.tplx . # for conversion, the template file must be in the same directory (or in templates/html dir)
for f in $listOfFiles
do
temp=${f%.ipynb}_tmp.ipynb
cp $f $temp
# corrections in some markdown cells
perl -pi -e s/'\\\\\['/'\$\$'/ $temp
perl -pi -e s/'\\\\\]'/'\$\$'/ $temp
# convert ipynb to latex
ipython3 nbconvert --to latex --template thmsInNb_article $temp
#ipython nbconvert --to latex --template thmsInNb_book $temp
## postprocessing
python3 $SDIR/thmInNb_tolatex.py ${temp%.ipynb}.tex ${f%.ipynb}.tex #conversion of remaining environments
python3 $SDIR/texheaders_rm.py ${f%.ipynb}.tex #remove headers and footers (optional -- can be commented)
#python3 $SDIR/toc_and_cln.py ${f%.ipynb}.tex
# want to number everything
perl -pi -e s/'\\\['/'\\begin{equation}'/ ${f%.ipynb}.tex
perl -pi -e s/'\\\]'/'\\end{equation}'/ ${f%.ipynb}.tex
done
echo Cleaning...
rm *_tmp.*
#rm thmsInNb_article.tplx
File diff suppressed because one or more lines are too long
@@ -1,570 +0,0 @@
%~\par
%\newpage
% No prompt!
%\textbf{Input \#{}}%
\begin{lstlisting}
%%javascript
IPython.load_extensions('calico-document-tools');
\end{lstlisting}% No prompt!
%\textbf{Output \#{}}
%
\begin{verbatim}
<IPython.core.display.Javascript object>
\end{verbatim}
% No prompt!
%\textbf{Input \#{}}%
\begin{lstlisting}
%%javascript
IPython.load_extensions('latex_envs');
\end{lstlisting}% No prompt!
%\textbf{Output \#{}}
%
\begin{verbatim}
<IPython.core.display.Javascript object>
\end{verbatim}
% No prompt!
%\textbf{Input \#{}}%
\begin{lstlisting}
%%html
<style>
.prompt{
display: none;
}
</style>
\end{lstlisting}
\section{Goal}\label{goal}
\subsection{Initial goal}\label{initial-goal}
The initial goal was only to add an environment \texttt{theorem} in my
workflow. That is to be able to type something like
\begin{listing}
\begin{theorem}
Let $u$ and $v$ be two vectors of $\mathbb{R}^n$. The dot product can be
expressed as \begin{equation}u^Tv = |u||v| \cos \theta,\end{equation} where $\theta$ is the angle
between $u$ and $v$ \ldots{}
\end{theorem}
\end{listing}
in a markdown cell and have it rendered, like
\begin{theorem}
Let $u$ and $v$ be two vectors of $\mathbb{R}^n$. The dot product can be
expressed as \begin{equation}u^Tv = |u||v| \cos \theta,\end{equation} where $\theta$ is the angle
between $u$ and $v$ \ldots{}
\end{theorem}
\subsection{Features}\label{features}
The initial project has evolved to account for more environments and
introduce some other features.
\subsubsection{Support for simple LaTeX
commands}\label{support-for-simple-latex-commands}
We also added some LaTeX commands (e.g. \texttt{\textbackslash{}textit},
\texttt{\textbackslash{}textbf}, \texttt{\textbackslash{}underline}) --
this is useful in the case of copy-paste from a LaTeX document. Labels
and references are supported, including for equations.
\subsubsection{Available environments}\label{available-environments}
\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
\textbf{theorems-like environments}: \emph{property, theorem, lemma,
corollary, proposition, definition,remark, problem, exercise,
example},
\item
\textbf{lists}: \emph{enumerate, itemize},\\
\item
limited support for a \emph{figure} environment,
\item
an environment \emph{listing},
\item
\emph{textboxa}, wich is a \texttt{textbox} environment defined as a
demonstration (see below).
\end{itemize}
More environments can be added easily in the javascript source file
\texttt{thmsInNb.js}. The rendering is done according to the stylesheet
\texttt{latex\_env.css}, which can be customized.
\subsubsection{Automatic numerotation}\label{automatic-numerotation}
Counters for numbering are implemented: one for theorems-like
environments, a second for exercises-like environments and a third one
for numbering figures.\\Mathjax-equations with a label are also numbered
document-wide (in contrast with standard notebook/mathjax numbering
where the scope of numbering is limited to cells). An anchor is created
for any label which enables to links things in the document:
\texttt{\textbackslash{}label} and \texttt{\textbackslash{}ref} are both
supported. A limitation is that numbering is updated (incremented) each
time a cell is rendered. A toolbar button is provided to reset the
counters and refresh the rendering of the whole document.
\subsubsection{Other features}\label{other-features}
\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
It is possible to mix LaTeX and markdown markup in environments\\
\item
Environments can be nested. However, this is not always
perfect\ldots{}
\end{itemize}
\section{Usage and examples}\label{usage-and-examples}
\subsection{Installation}\label{installation}
The extension consists in two javascript scripts:
\texttt{latex\_envs.js}, \texttt{thmsInNb.js} together with a stylesheet
\texttt{latex\_envs.css}. Follow the instructions in the
\href{https://github.com/ipython-contrib/IPython-notebook-extensions/wiki}{wiki}
to install the extension. You can simply copy these files in the
notebook extension directory (usually
\textasciitilde{}/.ipython/nbextensions) and load the extension in the
notebook by
\begin{verbatim}
%%javascript
IPython.load_extensions('latex_envs');
\end{verbatim}
\subsection{A first example}\label{a-first-example}
This example shows another example of environment, featuring automatic
numerotation, and the use of labels and references. Also note that
standard markdown can be present in the environment and is interpreted.
\emph{The rendering is done according to the stylesheet
\texttt{latex\_env.css}, which of course, can be tailored to specific
uses and tastes}.
\begin{listing}
\begin{definition}
\label{def:FT} Let $x[n]$ be a sequence of length $N$. Then, its
\textbf{Fourier transform} is given by
\begin{equation}
\label{eq:FT}
X[k]= \frac{1}{N} \sum_{n=0}^{N-1} x[n] e^{-j2\pi \frac{kn}{N}}
\end{equation}
\end{definition}
\end{listing}
\begin{definition}
\label{def:FT} Let $x[n]$ be a sequence of length $N$. Then, its
\textbf{Fourier transform} is given by
\begin{equation}
\label{eq:FT2}
X[k]= \frac{1}{N} \sum_{n=0}^{N-1} x[n] e^{-j2\pi \frac{kn}{N}}
\end{equation}
\end{definition}
This is an extremely important tool in signal processing. We put this in
evidence using the \texttt{textboxa} environment -- which is defined
here in the css, and that one should define in the LaTeX counterpart:
\begin{listing}
\begin{textboxa}
The Fourier transform is an extremely useful tool to have in your toolbox!
\end{textboxa}
\end{listing}
\begin{textboxa}
The Fourier transform is an extremely useful tool to have in your toolbox!
\end{textboxa}
As an example, consider the Fourier transform (\ref{eq:FT2}) of a pure
cosine wave given by \begin{equation}
x[n]= \cos(2\pi k_0 n/N),
\end{equation} where $k_0$ is an integer. Its Fourier transform is given by \begin{equation}
X[k] = \frac{1}{2} \left( \delta[k-k_0] + \delta[k-k_0] \right),
\end{equation} modulo $N$. This is illustrated in the following simple script:
% No prompt!
%\textbf{Input \#{}}%
\begin{lstlisting}
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from numpy.fft import fft
k0=4; N=128; n=np.arange(N); k=np.arange(N)
x=np.sin(2*np.pi*k0*n/N)
X=fft(x)
plt.stem(k,np.abs(X))
plt.xlim([0, 20])
plt.title("Fourier transform of a cosine")
_=plt.xlabel("Frequency index (k)")
\end{lstlisting}% No prompt!
%\textbf{Output \#{}}
%
\begin{center}
\adjustimage{max size={0.6\linewidth}{0.6\paperheight}}{latex_env_doc_tmp_files/latex_env_doc_tmp_26_0.png}
\end{center}
% { \hspace*{\fill} \\}
\subsection{Second example}\label{second-example}
This example shows a series of environments, with different facets;
\textbf{links, references, markdown or/and LaTeX formatting within
environments}. Again, the rendering is done according to the stylesheet
\texttt{latex\_env.css}, which can be tailored. The listing of
environments below is typed using the environment \emph{listing}\ldots{}
\begin{listing}
\begin{definition}
\label{def:diffeq} We call \textbf{difference equation} an equation of
the form \begin{equation}
\label{eq:diffeq}
y[n]= \sum_{k=1}^{p} a_k y[n-k] + \sum_{i=0}^q b_i x[n-i]
\end{equation}
\end{definition}
\begin{property}
If all the $a_k$ in equation (\ref{eq:diffeq}) of definition
\ref{def:diffeq} are zero, then the filter has a \textbf{finite impulse
response}.
\end{property}
\begin{proof}
Let $\delta[n]$ denote the Dirac impulse. Take $x[n]=\delta[n]$ in
(\ref{eq:diffeq}). This yields, by definition, the impulse response: \begin{equation}
\label{eq:fir}
h[n]= \sum_{i=0}^q b_i \delta[n-i],
\end{equation} which has finite support.
\end{proof}
\begin{theorem}
The poles of a causal stable filter are located within the unit circle
in the complex plane.
\end{theorem}
\begin{example}
\label{ex:IIR1} Consider $y[n]= a y[n-1] + x[n]$. The pole of the
transfer function is $z=a$. The impulse response $h[n]=a^n$ has infinite
support.
\end{example}
In the following exercise, you will check that the filter is stable iff $a$<1.
\begin{exercise}
\label{ex:exofilter} Consider the filter defined in Example
\ref{ex:IIR1}. Using the \textbf{function} \texttt{lfilter} of scipy,
compute and plot the impulse response for several values of $a$.
\end{exercise}
\end{listing}
The lines above are rendered as follows (of course everything can be
tailored in the stylesheet):
\begin{definition}
\label{def:diffeq} We call \textbf{difference equation} an equation of
the form
\begin{equation}
\label{eq:diffeq}
y[n]= \sum_{k=1}^{p} a_k y[n-k] + \sum_{i=0}^q b_i x[n-i]
\end{equation}
\end{definition}
Properties of the filter are linked to the coefficients of the
difference equation. For instance, an immediate property is
\begin{property}
If all the $a_k$ in equation (\ref{eq:diffeq}) of definition
\ref{def:diffeq} are zero, then the filter has a \textbf{finite impulse
response}.
\end{property}
\begin{proof}
Let $\delta[n]$ denote the Dirac impulse. Take $x[n]=\delta[n]$ in
(\ref{eq:diffeq}). This yields, by definition, the impulse response:
\begin{equation}
\label{eq:fir}
h[n]= \sum_{i=0}^q b_i \delta[n-i],
\end{equation}
which has finite support.
\end{proof}
\begin{theorem}
The poles of a causal stable filter are located within the unit circle
in the complex plane.
\end{theorem}
\begin{example}
\label{ex:IIR1} Consider $y[n]= a y[n-1] + x[n]$. The pole of the
transfer function is $z=a$. The impulse response $h[n]=a^n$ has infinite
support.
\end{example}
In the following exercise, you will check that the filter is stable iff
$a$\textless{}1.
\begin{exercise}
\label{ex:exofilter} Consider the filter defined in Example
\ref{ex:IIR1}. Using the \textbf{function} \texttt{lfilter} of scipy,
compute and plot the impulse response for several values of $a$.
\end{exercise}
\begin{listing}
The solution of exercise \ref{ex:exofilter}, which uses a difference equation as in Definition \ref{def:diffeq}:
\end{listing}
The solution of exercise \ref{ex:exofilter}, which uses a difference
equation as in Definition \ref{def:diffeq}:
% No prompt!
%\textbf{Input \#{}}%
\begin{lstlisting}
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import lfilter
d=np.zeros(100); d[0]=1 #dirac impulse
alist=[0.2, 0.8, 0.9, 0.95, 0.99, 0.999, 1.001, 1.01]
for a in alist:
h=lfilter([1], [1, -a],d)
_=plt.plot(h, label="a={}".format(a))
plt.ylim([0,1.5])
plt.xlabel('Time')
_=plt.legend()
\end{lstlisting}% No prompt!
%\textbf{Output \#{}}
%
\begin{center}
\adjustimage{max size={0.6\linewidth}{0.6\paperheight}}{latex_env_doc_tmp_files/latex_env_doc_tmp_32_0.png}
\end{center}
% { \hspace*{\fill} \\}
Finally, it is sometimes useful to integrate a figure within a markdown
cell. The standard markdown markup for that is
\texttt{!{[}link{]}(image)}, but a limitation is that the image can not
be resized, can not be referenced and is not numbered. Furthermore it
can be useful to re-use existing code. Threfore we have added a limited
support for the \texttt{figure} environment. This enables to do
something like
\begin{listing}
\begin{figure}[H]
\centerline{\includegraphics[width=10cm]{example.png}}
\caption{\label{fig:example} This is an example of figure included using LaTeX commands.}
\end{figure}
\end{listing}
which renders as
\begin{figure}[H]
\centerline{\includegraphics[width=10cm]{example.png}}
\caption{\label{fig:example} This is an example of figure included using LaTeX commands.}
\end{figure}
Of course, this Figure can now be referenced:
\begin{listing}
Figure \ref{fig:example} shows a second filter with input $X_2$, output $Y_2$ and an impulse response denoted as $h_2(n)$
\end{listing}
Figure \ref{fig:example} shows a second filter with input $X_2$, output
$Y_2$ and an impulse response denoted as $h_2(n)$
\subsection{Third example:}\label{third-example}
This example shows that environments like itemize or enumerate are also
available. As already indicated, this is useful for copying text from a
TeX file. Following the same idea, text formating commands
\texttt{\textbackslash{}textit}, \texttt{\textbackslash{}textbf},
\texttt{\textbackslash{}underline}, etc are also available.
\begin{listing}
The following \textit{environments} are available:
\begin{itemize}
\item \textbf{Theorems and likes}
\begin{enumerate}
\item theorem,
\item lemma,
\item corollary
\item ...
\end{enumerate}
\item \textbf{exercises}
\begin{enumerate}
\item problem,
\item example,
\item exercise
\end{enumerate}
\end{itemize}
\end{listing}
which gives\ldots{}
The following \textit{environments} are available:
\begin{itemize}
\item \textbf{Theorems and likes}
\begin{enumerate}
\item theorem,
\item lemma,
\item corollary
\item ...
\end{enumerate}
\item \textbf{exercises}
\begin{enumerate}
\item problem,
\item example,
\item exercise
\end{enumerate}
\end{itemize}
\section{(post)-Converters}\label{post-converters}
The extension works in the live-notebook. Since it relies on a bunch of
javascript, the notebook does not render as is in very nice services
such as \texttt{nbviewer} or \texttt{github} viewer. Similarly,
\texttt{nbconvert} does not know of the LaTeX constructs which are used
and therefore do not fully convert notebooks making use of this
extension. Therefore, it is necessary to add a post conversion step to
conversions provided by \texttt{nbconvert}. Though an interface exists
for adding post-converters to nbconvert, this (first) author was too
lazy and not enough strong to implement the post conversion along these
lines. What has be done are simple \texttt{bash} and \texttt{python}
scripts that perform this conversion.
\subsection{Installation}\label{installation}
Copy the scripts files to a directory in your search path, or launch the
scripts with the complete path. The two main scripts are
\texttt{ipynb\_thms\_to\_html} (conversion to html, of course:) and
\texttt{ipynb\_thms\_to\_latex} (conversion to LaTeX!).
\subsection{Conversion to html}\label{conversion-to-html}
\textbf{Requirements}: You will need \texttt{perl}, \texttt{nodejs}, and
\texttt{ipython3} (the script calls \texttt{ipython3}; if your
interpreter is \texttt{ipython}, edit the script and replace the
different occurences).
The conversion to html is done by something like
\begin{verbatim}
[path/]ipynb_thms_to_html filename
\end{verbatim}
or a list of files such as
\begin{verbatim}
[path/]ipynb_thms_to_html *.ipynb
\end{verbatim}
In turn, this script makes somes substitutions using \texttt{perl}, and
then uses the \texttt{nodesj} javascript interpreter to make the very
same substitutions that are done in the live notebook. The conversion
uses the template \texttt{thmsInNb.tpl} (located in the script
directory). It also copies the css \texttt{latex\_env.css} in the
directory of the output html file (it must be copied with html files in
the case of web upload).
\subsection{Conversion to LaTeX}\label{conversion-to-latex}
\textbf{Requirements}: You will need \texttt{perl} and
\texttt{ipython3}.
The conversion to LaTeX is done by something like
\begin{verbatim}
[path/]ipynb_thms_to_latex filename
\end{verbatim}
or a list of files such as
\begin{verbatim}
[path/]ipynb_thms_to_latex *.ipynb
\end{verbatim}
The script makes some substitutions and cleaning in arkdown cells, then
calls the legacy \texttt{nbconvert}. Afterward, it runs through the
LaTeX environments and converts their contents (which can contain
markdown markup) to LaTeX. Note that the script contains a list of the
LaTeX environments to process. In the case of the addition of an
environment in the main javascript (\texttt{thmsInNb.js}), this list
must also be updated.
Finally, the script removes the header and footer in the LaTeX file.
This is a personnal choice, and the corresponding line can be safely
commented.
\begin{example}
As for an example, the present document has been converted using
\begin{verbatim}
ipynb_thms_to_latex latex_env_doc.ipynb
\end{verbatim}
Then the resulting file (without header/footer) has been included in the
main file \texttt{documentation.tex}, where some LaTeX definitions of
environments are done (namely listings, colors, etc) and compiled using
\begin{verbatim}
xelatex documentation
\end{verbatim}
The output can be consulted \href{documentation.pdf}{here}.
\end{example}
\section{Disclaimer, sources and
thanks}\label{disclaimer-sources-and-thanks}
This is a not-quick but certainly dirty hack. I am a complete beginner
in javascript and of course there are obviously a large amount of
possible improvements of the code, in cleaning, factorizing, etc!
Language also needs improvement.
\textbf{Contributions will be welcome and deeply appreciated.}
Originally, I used a piece of code from the nice online markdown editor
\texttt{stackedit}
\url{https://github.com/benweet/stackedit/issues/187}, where the authors
also considered the problem of incorporating LaTeX markup in their
markdown. I also used examples and code from
\url{https://github.com/ipython-contrib/IPython-notebook-extensions}.
% No prompt!
%\textbf{Input \#{}}%
\begin{lstlisting}
%%javascript
IPython.load_extensions('latex_envs');
\end{lstlisting}% No prompt!
%\textbf{Output \#{}}
%
\begin{verbatim}
<IPython.core.display.Javascript object>
\end{verbatim}
% Add a bibliography block to the postdoc
%\bibliographystyle{ieetran}
%\bibliography{Thesis}
@@ -1,239 +0,0 @@
/* <!-- Load mathjax -->
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }, # Add this line-->
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true
},
// Center justify equations in code and markdown cells. Elsewhere
// we use CSS to left justify single line equations in code cells.
displayAlign: 'center',
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}},
linebreaks: { automatic: true }
}
});
</script>
<!-- End of mathjax configuration -->
*/
/*****************************************************************
LaTeX things
*****************************************************************/
.latex_tmp {text-align: justify;}
.latex_prob,
.latex_examp,
.latex_excs,
.latex_problem,
.latex_example,
.latex_exercise,
.latex_proof {
font-style: normal;
text-align: justify;
margin-left: 0px;
margin-right: 10px;
margin-top: 0px;
margin-bottom: 15px;
background-color: #CCFFCC;
display: block;
}
.latex_title {
float: left;
font-weight: bold;
padding-right: 10px;
}
.latex_proofend {
float: right;
}
.latex_listing {
display: block;
text-align: justify;
margin-right: 30px;
font-family: 'Lucida Sans Typewriter';
color:black;
background-color: GhostWhite ;
}
.rendered_html pre, .rendered_html code {
border: 0;
background-color: rgba(161, 139, 139, 0);
/* color: #000; */
font-size: 100%;
padding: 0;
}
.latex_thm, .latex_theorem, .latex_lem, .latex_cor, .latex_defn, .latex_prop, .latex_rem, .latex_property,
.latex_lemma, .latex_corollary, .latex_definition, .latex_proposition, .latex_remark, .latex_proof {
display: block;
text-align: justify;
margin-right: 10px;
margin-left: 0px;
margin-top: 0px;
margin-bottom: 15px;
font-style: italic;
color:black;
background-color: beige;
}
.latex_textboxa {
display: block;
font-weight: bold;
text-align: center;
width: 80%;
margin: auto;
border: 2px solid;
padding-top: 5px;
padding-bottom: 5px;
background-color: #f2dede;
border-color: #eed3d7;
color: #CC0099;
border-radius: 8px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px
}
img.latex_img {
display: block;
margin: auto;
/*height: XXXpx; /* */
width: 75%;
}
p.latex_img {
display: block;
width: 85%;
margin: auto;
text-align: justify;
}
/*****************************************************************
GENERAL CONFIG
*****************************************************************/
@font-face {
font-family: "Computer Modern";
src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunss.otf');
}
@font-face {
font-family: "Computer Modern";
font-weight: bold;
src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsx.otf');
}
@font-face {
font-family: "Computer Modern";
font-style: oblique;
src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsi.otf');
}
*/
/* @font-face {
font-family: "Computer Modern";
font-style: Typewriter;
src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmuntt.otf');
}*/
@font-face {
font-family: "Computer Modern";
font-weight: bold;
font-style: oblique;
src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunso.otf');
}
div.cell{
width:100%;
margin-left:auto; /*16% !important;* was preconised but pbs with some browsers*/
margin-right:auto;
}
h1 {
font-family: Helvetica, serif;
}
h2 {
font-family: Helvetica, serif;
color: darkblue;
}
h4{
margin-top:12px;
margin-bottom: 3px;
}
.rendered_html p {text-align:justify}
div.text_cell_render{
font-family: "Computer Modern", Arial, "Helvetica Neue", Helvetica, Geneva, sans-serif;
line-height: 145%;
font-size: 130%;
color: black;
width:100%;
/*width:800px;*/
margin-left:0px;
margin-right:auto;
}
.CodeMirror{
font-family: "Source Code Pro", source-code-pro,Consolas, monospace;
color: darkblue;
}
/* commented because many people prefer to have the prompt
.prompt{
display: None;
}
*/
/*
div.output_area
{
display: block;
margin-left: auto;
margin-right: auto
}
*/
div.output_subarea.output_text
{
margin-left: +2%;
}
div.output_subarea.output_png
{
margin-left: +10%;
}
div.output_subarea.output_svg
{
margin-left: +10%;
}
.text_cell_render h5 {
font-weight: 300;
font-size: 22pt;
color: #4057A1;
font-style: italic;
margin-bottom: .5em;
margin-top: 0.5em;
display: block;
}
.warning{
color: rgb( 240, 20, 20 )
}
@@ -1,37 +0,0 @@
// Node.js script for html to html conversion,
// substituting html classes to LaTeX theorem like environment constructs
// This applies the same substitutions
// that we use in the live notebook .
// read the markdown from stdin
var html_to_analyse='';
process.stdin.on("data", function (data) {
html_to_analyse += data;
});
// perform the html transform once stdin is complete
process.stdin.on("end", function () {
var fs = require('fs');
var IPython;
var static_path = "/usr/share/ipython/notebook/static/";
var marked = require( static_path + 'components/marked/lib/marked.js');
var eqNum = 0; // begins equation numbering at eqNum+1
var eqLabelWithNumbers = true; //if true, label equations with equation numbers; otherwise using the tag specified by \label
var conversion_to_html = true;
// Read the actual conversion script file, located in $HOME/.ipython/nbextensions
eval(fs.readFileSync( process.env['HOME'] + "/.ipython/nbextensions/thmsInNb.js", 'utf8') );
//IPython.mathjaxutils.init();
var html_converted = thmsInNbConv(marked,html_to_analyse);
process.stdout.write(html_converted);
});
-24
View File
@@ -1,24 +0,0 @@
This directory contains utilitary functions used to convert the notebook, with embedded LaTeX structures, to LaTeX or html.
Procedures are detailed in the documentation latex_env_doc.* and documentation.pdf.
Files
-----
File | description
----------------------- | -----------------------------
documentation.pdf | Documentation (pdf version) -- look at html and notebook version latex_env_doc.*
documentation.tex | Master file for producing documentation (includes latex_env_doc.tex)
header.tex | Header used for LaTeX compilation
ipynb_thms_to_html | Converter from ipynb to html
ipynb_thms_to_latex | Converter from ipynb to LaTeX
latex_env_doc.ipynb | Documentation and demo notebook
latex_env_doc.tex | Documentation and demo converted to LaTeX
latex_env_doc_tmp_files | temporary files from conversion
post_html_thms.js | Utilitary script used during ipynb --> html conversion
readme.md | This file
texheaders_rm.py | Utilitary script used during ipynb --> LaTeX conversion (removes header/footer)
thmInNb_tolatex.py | Utilitary script used during ipynb --> LaTeX conversion
thmsInNb_article.tplx | Template for LaTeX conversion (article style)
thmsInNb_book.tplx | Template for LaTeX conversion (book style)
thmsInNb.tpl | Template for html conversion
@@ -1,86 +0,0 @@
"""
Created on Thu Nov 18 15:34:38 2014
@author: bercherj
Remove TeX's file headers and footers
"""
import glob
import os
import sys
import time
from stat import *
def texheaders_filtering(input_file):
import re
st = os.stat(input_file)
atime = st[ST_ATIME] #access time
mtime = st[ST_MTIME] #modification time
with open(input_file,'rt') as f:
text=f.read()
#print(text)
my_texfile = input_file #file.split('.html')[0] + 'b.html'
if sys.version_info >= (3,0,0):
my_texfile_desc = open(my_texfile, 'wt', newline='')
else:
my_texfile_desc = open(my_texfile_file, 'wt')
tex_text=re.search('begin{document}([\s\S]*?)\\\\end{document}',text,flags=re.M)
#print(tex_text)
newtext=tex_text.group(1)
newtext=newtext.replace('\maketitle','')
newtext=newtext.replace('\\tableofcontents','')
my_texfile_desc.write(newtext)
#modify the file timestamp
my_texfile_desc.close()
os.utime(my_texfile,(atime,mtime))
verbose=True
if __name__ == '__main__':
import argparse
whatitdoes="""This program filters a tex file in order to remove headers
and footer, that is all what is before the \\begin{document} (included) and
after the \\end{document} (included)"""
myself="(c) JFB 2014"
parser = argparse.ArgumentParser(description=whatitdoes, epilog=myself)
# mandatory argument
parser.add_argument(
help = 'List of files to filter (accepts regular expressions)',
dest = 'argfiles', default = '*.tex', type = str, nargs = '*')
# verbosity flag
parser.add_argument('-v','--verbose', help = 'Prints information',
dest = 'verbose', default = False, #action='store_true'
action='count')
arguments = parser.parse_args()
verbose=arguments.verbose
if verbose==2: print("script arg: ", arguments.argfiles)
if isinstance(arguments.argfiles,list):
tex_files=[]
for x in arguments.argfiles:
tex_files = tex_files+glob.glob(x)
else:
tex_files = glob.glob(arguments.argfiles)
if verbose==2: print("glog.glog expansion: ", tex_files, '\n')
if len(tex_files ) == 0:
raise RuntimeError('No TeX files to convert.')
for file in tex_files:
if verbose:
print("Filtering {}".format(file))
texheaders_filtering(file)
@@ -1,57 +0,0 @@
# -*- coding: utf-8 -*-
"""
@author: bercherj
The content of selected environments is translated from markdown to latex, via pandoc
The environments are extracted recursively and translated. Then they are inserted back into the tex file.
"""
#****************************************************************************
def EnvReplace(message):
import re
from IPython.nbconvert.utils.pandoc import pandoc
environmentMap = ['thm','lem', 'cor', 'prop','defn','rem','prob','excs','examp','theorem','lemma','corollary','proposition',
'definition','remark','problem', 'exercise', 'example','proof','property']
# this map should match the map defined in .ipython/nbextensions/thmsInNb.js
def replacement(a):
w=a.group(0)
theenv=a.group(1)
tobetranslated=a.group(2)
if theenv in environmentMap:
out=pandoc(tobetranslated, 'markdown', 'latex')
result = '/begin{' + theenv + '}\n'+ out + '\n\end{' + theenv + '}';
else:
result = '/begin{' + theenv + '}'+ tobetranslated + '\end{' + theenv + '}';
#the transform \begin --> /begin is done in order to avoid the group to match again
#print(result)
return result
code="Init"
data=message
while (code!=None):
code=re.search(r'\\begin{(\w+)}([\s\S]*?)\\end{\1}', data)
data=re.sub(r'\\begin{(\w+)}([\s\S]*?)\\end{\1}', replacement, data)
return data
#while (message.match(/\\begin{(\w+)}([\s\S]*?)\\end{\1}/gm)!="") {
if __name__ == '__main__':
# TEST
import sys
infile=sys.argv[1]
outfile=sys.argv[2]
with open (sys.argv[1], "r") as infile:
text=infile.read()
text=text.replace("\\begin{document}","/begin{document}")
out=EnvReplace(text)
out=out.replace("/begin","\\begin")
with open (sys.argv[2], "w") as outfile:
outfile.write("%Thms like environments translated from notebook using thmInNb_tolatex.py\n")
outfile.write(out)
@@ -1,75 +0,0 @@
{%- extends 'full.tpl' -%}
{%- block header -%}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>[{{nb.metadata.name}}]</title>
{% for css in resources.inlining.css -%}
<style type="text/css">
{{ css }}
</style>
{% endfor %}
<style type="text/css">
/* Overrides of notebook CSS for static HTML export */
body {
overflow: visible;
padding: 8px;
}
.input_area {
padding: 0.2em;
}
pre {
padding: 0.2em;
border: none;
margin: 0px;
font-size: 13px;
}
</style>
<!-- Custom stylesheet, it must be in the same directory as the html file -->
<link rel="stylesheet" href="custom.css">
<link rel="stylesheet" href="latex_envs.css">
<!-- Load mathjax -->
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }, <!-- Add this line-->
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true
},
// Center justify equations in code and markdown cells. Elsewhere
// we use CSS to left justify single line equations in code cells.
displayAlign: 'center',
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}},
linebreaks: { automatic: true }
}
});
</script>
<!-- End of mathjax configuration -->
</head>
{%- endblock header -%}
{% block body %}
{{ super() }}
{%- endblock body %}
{% block footer %}
</html>
{% endblock footer %}
@@ -1,170 +0,0 @@
((*- extends 'article.tplx' -*))
((* block h1 -*))\section((* endblock h1 -*))
((* block h2 -*))\subsection((* endblock h2 -*))
((* block h3 -*))\subsubsection((* endblock h3 -*))
((* block h4 -*))\paragraph((* endblock h4 -*))
((* block h5 -*))\subparagraph((* endblock h5 -*))
((* block abstract *))
\tableofcontents
%~\par
%\newpage
((* endblock abstract *))
%or?
%((* block toc *))\tableofcontents((* endblock toc *))
%===============================================================================
% My custom output style
%===============================================================================
% A custom cell style that places code in a simple verbatim and prints "Input #"
% and "Output #" cell prompts.
((*- block in_prompt -*))
% No prompt!
%\textbf{Input \#{}(((cell.prompt_number)))}
((*- endblock in_prompt -*))
((*- block input -*))
%
\begin{lstlisting}
((( cell.source )))
\end{lstlisting}
((*- endblock input -*))
% ok
%but may be this?
%((*- block output_prompt -*))
% No prompt!
%\textbf{Output \#{}(((cell.prompt_number)))}
%((*- endblock output_prompt -*))
((* block author *))
\author{J.-F. Bercher}
((* endblock author *))
((* block title *))
\title{ }
((* endblock title *))
((* block packages *))
((( super() )))
\usepackage{listings}
((* endblock packages *))
%or -- both work
((* block header *))
((( super() )))
%\usepackage{foo}
((* endblock *))
((* block commands *))
% Prevent overflowing lines due to hard-to-break entities
\sloppy
% Setup hyperref package
\hypersetup{
breaklinks=true, % so long urls are correctly broken across lines
pdftitle={\@title},
pdfauthor={\@author},
colorlinks=true, %colorise les liens
breaklinks=true, %permet le retour à la ligne dans les liens trop longs
urlcolor= blue, %couleur des hyperliens
linkcolor= blue, %couleur des liens internes
citecolor=blue, %couleur des liens de citations
bookmarksopen=false,
pdftoolbar=false,
pdfmenubar=false,
% hidelinks
}
% Slightly bigger margins than the latex defaults
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
%listings configuration
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\lstset{
language=Python,
commentstyle=\color{mygreen},
keywordstyle=\color{blue},
stringstyle=\color{mymauve},
xleftmargin= 1cm,
xrightmargin= 1cm,
showstringspaces=false,
breaklines=true,
texcl=false,
% basicstyle=\ttfamily,
frame=single,
frameround=tttt,
framesep=10pt,
%framexleftmargin=10pt,
%framexrightmargin =10pt,
%frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}
inputencoding=utf8,
extendedchars=true,
literate=%
{é}{{\'{e}}}1
{è}{{\`{e}}}1
{ê}{{\^{e}}}1
{ë}{{\¨{e}}}1
{É}{{\'{E}}}1
{Ê}{{\^{E}}}1
{û}{{\^{u}}}1
{ù}{{\`{u}}}1
{à}{{\`{a}}}1
{ç}{{\c{c}}}1
{Ç}{{\c{C}}}1
{î}{{\^{i}}}1
{Î}{{\^{I}}}1
}
((* endblock commands *))
% Display latex
((* block data_latex -*))
((*- if output.latex.startswith('$'): -*))
((= Replace $ symbols with more explicit, equation block. =))
\begin{equation}
((( output.latex | strip_dollars )))
\end{equation}
((*- else -*))
((( output.latex )))
((*- endif *))
((* endblock data_latex *))
((* block bibliography *))
%\bibliographystyle{ieetran}
%\bibliography{Thesis}
((* endblock bibliography *))
% Draw a figure using the graphicx package.
((* macro draw_figure(filename) -*))
((* set filename = filename | posix_path *))
((*- block figure scoped -*))
\begin{center}
\adjustimage{max size={0.6\linewidth}{0.6\paperheight}}{((( filename )))}
\end{center}
% { \hspace*{\fill} \\}
((*- endblock figure -*))
((*- endmacro *))
%============================================================
((= This line selects the cell style. =))
%((* set cell_style = 'style_bw_python.tplx' *))
((* set cell_style = 'style_python.tplx' *))
@@ -1,171 +0,0 @@
((*- extends 'report.tplx' -*))
((* block h1 -*))\chapter((* endblock h1 -*))
((* block h2 -*))\section((* endblock h2 -*))
((* block h3 -*))\subsection((* endblock h3 -*))
((* block h4 -*))\subsubsection((* endblock h4 -*))
((* block h5 -*))\paragraph((* endblock h5 -*))
((* block abstract *))
\tableofcontents
%~\par
%\newpage
((* endblock abstract *))
%or?
%((* block toc *))\tableofcontents((* endblock toc *))
%===============================================================================
% My custom output style
%===============================================================================
% A custom cell style that places code in a simple verbatim and prints "Input #"
% and "Output #" cell prompts.
((*- block in_prompt -*))
% No prompt!
%\textbf{Input \#{}(((cell.prompt_number)))}
((*- endblock in_prompt -*))
((*- block input -*))
%
\begin{lstlisting}
((( cell.source )))
\end{lstlisting}
((*- endblock input -*))
% ok
%but may be this?
%((*- block output_prompt -*))
% No prompt!
%\textbf{Output \#{}(((cell.prompt_number)))}
%((*- endblock output_prompt -*))
((* block author *))
\author{J.-F. Bercher}
((* endblock author *))
((* block title *))
\title{ }
((* endblock title *))
((* block packages *))
((( super() )))
\usepackage{listings}
\usepackage{float}
((* endblock packages *))
%or -- both work
((* block header *))
((( super() )))
%\usepackage{foo}
((* endblock *))
((* block commands *))
% Prevent overflowing lines due to hard-to-break entities
\sloppy
% Setup hyperref package
\hypersetup{
breaklinks=true, % so long urls are correctly broken across lines
pdftitle={\@title},
pdfauthor={\@author},
colorlinks=true, %colorise les liens
breaklinks=true, %permet le retour à la ligne dans les liens trop longs
urlcolor= blue, %couleur des hyperliens
linkcolor= blue, %couleur des liens internes
citecolor=blue, %couleur des liens de citations
bookmarksopen=false,
pdftoolbar=false,
pdfmenubar=false,
% hidelinks
}
% Slightly bigger margins than the latex defaults
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
%listings configuration
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\lstset{
language=Python,
commentstyle=\color{mygreen},
keywordstyle=\color{blue},
stringstyle=\color{mymauve},
xleftmargin= 1cm,
xrightmargin= 1cm,
showstringspaces=false,
breaklines=true,
texcl=false,
% basicstyle=\ttfamily,
frame=single,
frameround=tttt,
framesep=10pt,
%framexleftmargin=10pt,
%framexrightmargin =10pt,
%frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}
inputencoding=utf8,
extendedchars=true,
literate=%
{é}{{\'{e}}}1
{è}{{\`{e}}}1
{ê}{{\^{e}}}1
{ë}{{\¨{e}}}1
{É}{{\'{E}}}1
{Ê}{{\^{E}}}1
{û}{{\^{u}}}1
{ù}{{\`{u}}}1
{à}{{\`{a}}}1
{ç}{{\c{c}}}1
{Ç}{{\c{C}}}1
{î}{{\^{i}}}1
{Î}{{\^{I}}}1
}
((* endblock commands *))
% Display latex
((* block data_latex -*))
((*- if output.latex.startswith('$'): -*))
((= Replace $ symbols with more explicit, equation block. =))
\begin{equation}
((( output.latex | strip_dollars )))
\end{equation}
((*- else -*))
((( output.latex )))
((*- endif *))
((* endblock data_latex *))
((* block bibliography *))
%\bibliographystyle{ieetran}
%\bibliography{Thesis}
((* endblock bibliography *))
% Draw a figure using the graphicx package.
((* macro draw_figure(filename) -*))
((* set filename = filename | posix_path *))
((*- block figure scoped -*))
\begin{center}
\adjustimage{max size={0.6\linewidth}{0.6\paperheight}}{((( filename )))}
\end{center}
% { \hspace*{\fill} \\}
((*- endblock figure -*))
((*- endmacro *))
%============================================================
((= This line selects the cell style. =))
%((* set cell_style = 'style_bw_python.tplx' *))
((* set cell_style = 'style_python.tplx' *))
@@ -1,125 +0,0 @@
"""
Created on Thu Nov 18 15:34:38 2014
@author: JF
"""
import glob
import os
import sys
import time
from stat import *
def texheaders_filtering(input_file):
import re
st = os.stat(input_file)
atime = st[ST_ATIME] #access time
mtime = st[ST_MTIME] #modification time
with open(input_file,'rt') as f:
text=f.read()
#print(text)
my_texfile = input_file #file.split('.html')[0] + 'b.html'
if sys.version_info >= (3,0,0):
my_texfile_desc = open(my_texfile, 'wt', newline='')
else:
my_texfile_desc = open(my_texfile_file, 'wt')
def remp(intext):
#out=re.findall('\\\\[sub]?section',intext.group(0))
out=re.findall('(\\\\[sub]?section|\\\\chapter)',intext.group(0))
print(out)
""""print(out.group(0))
return out.group(0) """
return out[-1]
#newtext=re.sub('section{Table of Contents}([\s\S]*?)\\[sub]?section{','Remplacement',text,flags=re.M)
newtext=re.sub('\\\\section{Table of Contents}([\s\S]*?)(\\\\[sub]?section|\\\\chapter)',remp,text,flags=re.M)
newtext=re.sub('\\\\begin{verbatim}[\s]*?<matplotlib\.[\S ]*?>[\s]*?\\\\end{verbatim}','',newtext,flags=re.M)
newtext=re.sub('\\\\begin{verbatim}[\s]*?<IPython\.core\.display[\S ]*?>[\s]*?\\\\end{verbatim}','',newtext,flags=re.M)
#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{3in}{0.4pt}\\\\end{center}[\s]*?\\\\href{toc.ipynb}{Index}[\S\s ]*?.ipynb}{Next}','',newtext,flags=re.M)
# figcaption(text,label=)
tofind="figcaption\(([\s\S]*?)\)\n([\s\S]*?)\\\\begin{center}\s*\\\\adjustimage[\s\S]*?}}{([\S]*?)}\s*\\\\end{center}"
def replacement(text):
cap=re.match("\"([\S\s]*?)\",[\S\s]*?label=\"([\S]*?)\"",text.group(1))
if cap==None:
cap=re.match("\"([\S\s]*?)\"",text.group(1))
caption=cap.group(1)
label=""
rep="\n%s\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\linewidth]{%s}\n\\caption{%s}\n\\end{figure}" % (text.group(2),text.group(3),caption)
else:
caption=cap.group(1)
label=cap.group(2)
rep="\n%s\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\linewidth]{%s}\n\\caption{%s}\n\\label{%s}\n\\end{figure}" % (text.group(2),text.group(3),caption,label)
return rep
code="Init"
while (code!=None):
code=re.search(tofind,newtext)
newtext=re.sub(tofind,replacement,newtext,flags=re.M)
my_texfile_desc.write(newtext)
#modify the file timestamp
my_texfile_desc.close()
os.utime(my_texfile,(atime,mtime))
verbose=True
if __name__ == '__main__':
import argparse
whatitdoes="""This program filters a LaTeX file \n
- in order to remove the first 'table of contents section',
to the next section ;
- it replaces figcaption structures to "\\caption{\\label{}}" LaTeX constructs.
- Finally, it also filters out various 'spurious' outputs"""
myself="(c) JFB 2014"
parser = argparse.ArgumentParser(description=whatitdoes, epilog=myself)
# mandatory argument
parser.add_argument(
help = 'List of files to filter (accepts regular expressions)',
dest = 'argfiles', default = '*.tex', type = str, nargs = '*')
# verbosity flag
parser.add_argument('-v','--verbose', help = 'Prints information',
dest = 'verbose', default = False, #action='store_true'
action='count')
arguments = parser.parse_args()
verbose=arguments.verbose
if verbose==2: print("script arg: ", arguments.argfiles)
if isinstance(arguments.argfiles,list):
tex_files=[]
for x in arguments.argfiles:
tex_files = tex_files+glob.glob(x)
else:
tex_files = glob.glob(arguments.argfiles)
if verbose==2: print("glog.glog expansion: ", tex_files, '\n')
if len(tex_files ) == 0:
raise RuntimeError('No TeX files to convert.')
for file in tex_files:
if verbose:
print("Filtering {}".format(file))
texheaders_filtering(file)
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-239
View File
@@ -1,239 +0,0 @@
/* <!-- Load mathjax -->
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }, # Add this line-->
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true
},
// Center justify equations in code and markdown cells. Elsewhere
// we use CSS to left justify single line equations in code cells.
displayAlign: 'center',
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}},
linebreaks: { automatic: true }
}
});
</script>
<!-- End of mathjax configuration -->
*/
/*****************************************************************
LaTeX things
*****************************************************************/
.latex_tmp {text-align: justify;}
.latex_prob,
.latex_examp,
.latex_excs,
.latex_problem,
.latex_example,
.latex_exercise,
.latex_proof {
font-style: normal;
text-align: justify;
margin-left: 0px;
margin-right: 10px;
margin-top: 0px;
margin-bottom: 15px;
background-color: #CCFFCC;
display: block;
}
.latex_title {
float: left;
font-weight: bold;
padding-right: 10px;
}
.latex_proofend {
float: right;
}
.latex_listing {
display: block;
text-align: justify;
margin-right: 30px;
font-family: 'Lucida Sans Typewriter';
color:black;
background-color: GhostWhite ;
}
.rendered_html pre, .rendered_html code {
border: 0;
background-color: rgba(161, 139, 139, 0);
/* color: #000; */
font-size: 100%;
padding: 0;
}
.latex_thm, .latex_theorem, .latex_lem, .latex_cor, .latex_defn, .latex_prop, .latex_rem, .latex_property,
.latex_lemma, .latex_corollary, .latex_definition, .latex_proposition, .latex_remark, .latex_proof {
display: block;
text-align: justify;
margin-right: 10px;
margin-left: 0px;
margin-top: 0px;
margin-bottom: 15px;
font-style: italic;
color:black;
background-color: beige;
}
.latex_textboxa {
display: block;
font-weight: bold;
text-align: center;
width: 80%;
margin: auto;
border: 2px solid;
padding-top: 5px;
padding-bottom: 5px;
background-color: #f2dede;
border-color: #eed3d7;
color: #CC0099;
border-radius: 8px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px
}
img.latex_img {
display: block;
margin: auto;
/*height: XXXpx; /* */
width: 75%;
}
p.latex_img {
display: block;
width: 85%;
margin: auto;
text-align: justify;
}
/*****************************************************************
GENERAL CONFIG
*****************************************************************/
@font-face {
font-family: "Computer Modern";
src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunss.otf');
}
@font-face {
font-family: "Computer Modern";
font-weight: bold;
src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsx.otf');
}
@font-face {
font-family: "Computer Modern";
font-style: oblique;
src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsi.otf');
}
*/
/* @font-face {
font-family: "Computer Modern";
font-style: Typewriter;
src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmuntt.otf');
}*/
@font-face {
font-family: "Computer Modern";
font-weight: bold;
font-style: oblique;
src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunso.otf');
}
div.cell{
width:100%;
margin-left:auto; /*16% !important;* was preconised but pbs with some browsers*/
margin-right:auto;
}
h1 {
font-family: Helvetica, serif;
}
h2 {
font-family: Helvetica, serif;
color: darkblue;
}
h4{
margin-top:12px;
margin-bottom: 3px;
}
.rendered_html p {text-align:justify}
div.text_cell_render{
font-family: "Computer Modern", Arial, "Helvetica Neue", Helvetica, Geneva, sans-serif;
line-height: 145%;
font-size: 130%;
color: black;
width:100%;
/*width:800px;*/
margin-left:0px;
margin-right:auto;
}
.CodeMirror{
font-family: "Source Code Pro", source-code-pro,Consolas, monospace;
color: darkblue;
}
/* commented because many people prefer to have the prompt
.prompt{
display: None;
}
*/
/*
div.output_area
{
display: block;
margin-left: auto;
margin-right: auto
}
*/
div.output_subarea.output_text
{
margin-left: +2%;
}
div.output_subarea.output_png
{
margin-left: +10%;
}
div.output_subarea.output_svg
{
margin-left: +10%;
}
.text_cell_render h5 {
font-weight: 300;
font-size: 22pt;
color: #4057A1;
font-style: italic;
margin-bottom: .5em;
margin-top: 0.5em;
display: block;
}
.warning{
color: rgb( 240, 20, 20 )
}
-178
View File
@@ -1,178 +0,0 @@
/*
*/
var eqNum = 0; // begins equation numbering at eqNum+1
var eqLabelWithNumbers = true; //if true, label equations with equation numbers; otherwise using the tag specified by \label
var conversion_to_html = false;
//var run_this = function() {
define(["require", "/nbextensions/thmsInNb.js"], function (require,thmsInNb) {
var maps = initmap();
environmentMap=maps[0];
cmdsMap=maps[1];
eqLabNums=maps[2];
//define(["require"], function (require) {
var load_css = function(name) {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = require.toUrl(name);
//link.href = name;
document.getElementsByTagName("head")[0].appendChild(link);
};
var load_ipython_extension = function() {
require(['components/marked/lib/marked'], function(marked) {
"use strict";
if (IPython.version[0] <= 2) {
console.log("This extension requires IPython >= 2.x")
return
}
var security = IPython.security;
var _on_reload = true; /* make sure cells render on reload */
/* Override original markdown render function */
/* The idea was took from python-markdown extension https://gist.github.com/juhasch/c37408a0d79156f28c17#file-python-markdown-js */
// This used to work in IPython 2.x
/* IPython.MarkdownCell.prototype.render = function() {
var cont = IPython.TextCell.prototype.render.apply(this);
console.log("result of textcell prototype",cont)
cont = cont || IPython.notebook.dirty || _on_reload
if (cont) {
console.log("overriding markdown cell renderer")
var text = this.get_text();
var math = null;
if (text === "") {
text = this.placeholder;
}
var text_and_math = IPython.mathjaxutils.remove_math(text);
text = text_and_math[0];
math = text_and_math[1];
console.log("text",text)
var html = marked.parser(marked.lexer(text));
html = IPython.mathjaxutils.replace_math(html, math);
html = thmsInNbConv(html); //<----- thmsInNb patch here
html = security.sanitize_html(html);
console.log("html",html)
html = $($.parseHTML(html));
// links in markdown cells should open in new tabs
html.find("a[href]").not('[href^="#"]').attr("target", "_blank");
this.set_rendered(html);
this.element.find('div.input_area').hide();
this.element.find("div.text_cell_render").show();
this.typeset();
}
return cont
};*/
// for IPython v 3
IPython.MarkdownCell.prototype.render = function () {
var cont = IPython.TextCell.prototype.render.apply(this);
if (cont || IPython.notebook.dirty || _on_reload) {
var that = this;
var text = this.get_text();
var math = null;
if (text === "") { text = this.placeholder; }
var text_and_math = IPython.mathjaxutils.remove_math(text);
text = text_and_math[0];
math = text_and_math[1];
marked(text, function (err, html) {
html = IPython.mathjaxutils.replace_math(html, math);
html = thmsInNbConv(marked,html); //<----- thmsInNb patch here
html = security.sanitize_html(html);
html = $($.parseHTML(html));
// add anchors to headings
html.find(":header").addBack(":header").each(function (i, h) {
h = $(h);
var hash = h.text().replace(/ /g, '-');
h.attr('id', hash);
h.append(
$('<a/>')
.addClass('anchor-link')
.attr('href', '#' + hash)
.text('¶')
);
});
// links in markdown cells should open in new tabs
html.find("a[href]").not('[href^="#"]').attr("target", "_blank");
that.set_rendered(html);
that.typeset();
that.events.trigger("rendered.MarkdownCell", {cell: that});
});
}
return cont;
};
var init_cells = function() {
var ncells = IPython.notebook.ncells();
var cells = IPython.notebook.get_cells();
var maps = initmap(); // this is to reset the counters in case of reload
environmentMap=maps[0]; cmdsMap=maps[1]; eqLabNums=maps[2];
eqNum = 0;
console.log("reloading cells");
for (var i = 0; i < ncells; i++) {
var cell = cells[i];
if (cell instanceof IPython.TextCell) {
cell.render();};
}
}
init_cells();
/* on reload */
$([IPython.events]).on('status_started.Kernel', function() {
init_cells();
_on_reload = false;
})
IPython.toolbar.add_buttons_group([
{
id : 'doReload',
label : 'latex_envs: Refresh rendering ',
icon : 'fa-retweet',
callback : init_cells
}
]);
});
};
console.log("Loading latex_envs.css");
//load_css('/nbextensions/latex_envs.css')
load_css('./latex_envs.css')
//load_ipython_extension();
return {
load_ipython_extension: load_ipython_extension,
};
}); //End of run_this
//run_this();
console.log("Loading ./latex_envs.js");
-7
View File
@@ -1,7 +0,0 @@
Type: IPython Notebook Extension
Name: (some) LaTeX environments for Jupyter
Description: Enable to use laTeX environments in Jupyter's markdown cells
Link: https://github.com/jfbercher/IPython-notebook-extensions/tree/master/testing/latex_envs/
Icon: icon.png
Main: latex_envs.js
Compatibility: 3.x
-51
View File
@@ -1,51 +0,0 @@
# (some) LaTeX environments for Jupyter notebook
This extension enables to use some LaTeX structures directly in markdown cells of the notebook. Supported structures include
- theorems like structures: theorem, lemma, corollary, definition, example, problem, ...
- itemize, enumerate, ...
More environments can be simply added in the source file (`thsInNb.js`).
An automatic numbering of environments is implemented. Labels, cross-references and links between environments and equations are supported.
In addition, the extension also enables to use simple LaTeX markup such as \textit{}, \textbf{}, \textem{}, \underline{}, etc.
This is useful for copying snippets of text to/from a LaTeX file.
The rendering of the LaTeX structures (theorems, definitions, exercises..) can be tailored via the stylesheet `latex_envs.css`
The `conversion` directory contains scripts for converting the notebooks to html and LaTeX while taking into account the structures
enabled by the extension. Theses scripts require nodejs, perl, ipython3.
# Installation
You should follow the instructions in the wiki. A manual installation consists in copying latex_envs.js, thmsInNb.js, latex_envs.css to
the notebook extension directory, usually ~/.ipython/nbextensions.
Copy the scripts in conversion/ to some directory (preferably in your path).
Either load the extension from your `custom.js` or use a code cell with
%%javascript
IPython.load_extensions('latex_envs');
# Demo/documentation
A demo notebook `latex_env_doc.ipynb` is provided. Its html version is [latex_env_doc.html](https://rawgit.com/jfbercher/IPython-notebook-extensions/master/testing/latex_envs/latex_env_doc.html) and a pdf resulting
from conversion to LaTeX is available as `documentation.pdf`. Code needs improvements.
**Contributions, comments, issues are most welcome and will be deeply appreciated.**
The original idea and starting code come from a discussion here: [https://github.com/benweet/stackedit/issues/187](https://github.com/benweet/stackedit/issues/187).
## Files
File | description
----------------------- | -----------------------------
conversion | Directory containing utilitary files for converting the notebook to html/LaTeX
documentation.pdf | Documentation
latex_env_doc.html | Documentation and demo notebook (html) version
latex_env_doc.ipynb | Documentation and demo notebook
latex_envs.css | Stylesheet for rendering the notebook/html
latex_envs.js | LaTeX_envs extension (main script)
thmsInNb.js | LaTeX_envs extension (does the actual conversion)
readme.md | This file.
-271
View File
@@ -1,271 +0,0 @@
/*
This script goes through the input text (actually it is triggered each time a markdown cell is rendered. The imput text is the content of the cell.
It replaces the latex structures by html tags, typically wit a <div class="latex_environment_name> ... </div>. Then the html rendering
can be tailored using a devoted css. The original idea comes from
https://github.com/benweet/stackedit/issues/187
where the contributors to stackedit, the online markdown editor, discussed the processing of LaTeX environments.
The code has evolved from this base and was adapted to the particular case and specificities of the Jupyter.
*/
function initmap(){
var eqLabNums = {};
var thmCounter = { num: 0 };
var excsCounter = { num: 0 };
var figCounter = { num: 0 };
var environmentMap = {
thm: { title: "Theorem" ,counter: thmCounter },
lem: { title: "Lemma" ,counter: thmCounter },
cor: { title: "Corollary" ,counter: thmCounter },
prop: { title: "Property" ,counter: thmCounter },
defn: { title: "Definition" ,counter: thmCounter },
rem: { title: "Remark" ,counter: thmCounter },
prob: { title: "Problem" ,counter: excsCounter },
excs: { title: "Exercise" ,counter: excsCounter },
examp: { title: "Example" ,counter: excsCounter },
property: { title: "Property" ,counter: thmCounter },
theorem: { title: "Theorem" ,counter: thmCounter },
lemma: { title: "Lemma" ,counter: thmCounter },
corollary: { title: "Corollary" ,counter: thmCounter },
proposition: { title: "Property" ,counter: thmCounter },
definition: { title: "Definition" ,counter: thmCounter },
remark: { title: "Remark" ,counter: thmCounter },
problem: { title: "Problem" ,counter: excsCounter },
exercise: { title: "Exercise" ,counter: excsCounter },
example: { title: "Example" ,counter: excsCounter },
figure: { title: "Figure" ,counter: figCounter },
itemize: { title: "Itemize" },
enumerate: { title: "Enumerate" },
listing: { title: " " },
textboxa: { title: " " },
proof: { title: "Proof" }
};
//This is to substitute simple LaTeX+argument commands
// For instance \textbf{foo} is replaced by <b> foo </b>
var cmdsMap = {
underline: { replacement: "u" },
textit: { replacement: "i" },
textbf: { replacement: "b" },
textem: { replacement: "em" },
section: { replacement: "h1" },
subsection: { replacement: "h2" },
}
return [environmentMap, cmdsMap, eqLabNums]
}
var maps = initmap();
environmentMap=maps[0];
cmdsMap=maps[1];
eqLabNums=maps[2];
/*********/
function thmsInNbConv(marked,text) {
var listings = [];
{ //****************************************************************************
var EnvReplace = function(message) {
//console.log(message);
//Look for pairs [ ]
var message = message.replace(/^(?:<p>)?\[([\s\S]*?)^(?:<p>)?\]/gm,
function(wholeMatch, m1) {
//return "\\["+m1+"\\]";
m1 = m1.replace(/<[/]?em>/g, "_"); //correct possible incorrect md remplacements in eqs
m1 = m1.replace(/left{/g, "left\\{"); //correct possible incorrect md remplacements in eqs
return "\\[" + m1 + "\\]";
}
);
var message = message.replace(/(?:<p>)?([$]{1,2})([\s\S]*?)(?:<p>)?\1/gm,
function(wholeMatch, m1) {
//return "\\["+m1+"\\]";
wholeMatch = wholeMatch.replace(/<[/]?em>/g, "_"); //correct possible incorrect md remplacements in eqs
wholeMatch = wholeMatch.replace(/left{/g, "left\\{"); //correct possible incorrect md remplacements in eqs
return wholeMatch;
}
);
var out = message.replace(/\\begin{(\w+)}([\s\S]*?)\\end{\1}/gm, function(wholeMatch, m1, m2) {
//if(!environmentMap[m1]) return wholeMatch;
var environment = environmentMap[m1];
if (!environment) return wholeMatch;
var title = environment.title;
if (environment.counter) {
environment.counter.num++;
title += ' ' + environment.counter.num;
}
//The conversion machinery (see marked.js or mathjaxutils.js) extracts text and math and converts text to markdown.
//Here, we also want to convert thm like env.
//So we do it here. However, environments with blank lines are *not* extracted before and thus already converted.
// Thus we avoid to process them again.
// Try to check if there is remaining Markdown
// |\n\s-[\s]*(\w+)/gm
// /\*{1,2}([\s\S]*?)\*{1,2}|\_{1,2}([\s\S]*?)\_{1,2}/gm)
if (m2.match(/\*{1,2}([\s\S]*?)\*{1,2}|\_{1,2}([\S]*?)\_{1,2}|```/gm)) {
var m2 = marked.parser(marked.lexer(m2));
}
var result = '<span class="latex_title">' + title + '</span> <div class="latex_' + m1 + '">' + m2;
// case of the figure environment. We look for an \includegraphics directive, gobble its parameters except the image name,
// look for a caption and a label and construct an image representation with a caption and an anchor. Style can be customized
// via the class latex_img
if (m1 == "figure") {
var caption = /\\caption{([\s\S]*?)}/gm.exec(m2)[1];
var graphic = /\\includegraphics(?:[\S\s]*?){([\s\S]*?)}/gm.exec(m2)[1];
var label = m2.match(/<a id=([\s\S]*?)a>/gm);
if (!caption.match(/<a id=([\s\S]*?)a>/gm)) {caption=label+caption};
var result = '<div class="latex_figure"> <img class="latex_img" src="'+graphic+'"> <p class="latex_img"> ' + title+': ' + caption + '</p>';
};
if (m1 == "proof") {
result += '<span class="latex_proofend" style="float:right">■</span>';
}
if (m1 == "itemize") {
var result = "<div><ul>" + m2.replace(/\\item/g, "<li>") + "</ul>";
};
if (m1 == "enumerate") {
var result = "<div><ol>" + m2.replace(/\\item/g, "<li>") + "</ol>";
};
if (m1 != "listing") {
result = EnvReplace(result);
}; //try to do further replacements
return result + '</div>';
});
//out = EnvReplace(out);
return out; //}
}
}
//**********************************************************************************
// What follows is done on the whole text, environments included:
// - substitutions of labels with anchors
// - substitutions of ref with links
// - LaTeX commands (textbf, textit, etc) replaced by html tags
// We want to preserve a "listing" environment from **any modification**
// therefore we remove them and insert them back at the end
var remove_listing = function (text) {
text = text.replace(/\\begin{listing}([\s\S]*?)\\end{listing}/gm, function(wholeMatch, m1) {
listings.push(m1);
return '!@!Listing'+listings.length+'!@!'; //originallistings location are marked by !@!Listingn!@!, n being the index of listing
});
return text;
};
text = remove_listing(text)
// Now we can do our stuff
{
// This is to replace references by links to the correct environment,
//while preserving links to equations
// which are worked out by MathJax
//LABELS
var text = text.replace(/\\label{(\S+):(\S+)}/g, function(wholeMatch, m1, m2) {
m2 = m2.replace(/<[/]?em>/g, "_");
if (m1 == "eq") {
if (conversion_to_html) {
/* if (eqLabelWithNumbers) {
eqNum++;
return wholeMatch + '\\tag{'+eqNum+'}' ;
*/
return wholeMatch; //+ '\\tag{'+m1+':'+m2+'}' ;
} else {
if (eqLabelWithNumbers) {
eqNum++;
//return '<a id="' + m1 + m2 + '">' + '['+m1+':'+m2+']' + '</a>' + '\\tag{'+eqNum+'}' ;
eqLabNums[m2] = eqNum.toString();
return '\\tag{' + eqNum + '}' + '<!--' + wholeMatch + '-->' ;
}
return '\\tag{' + m2 + '}' + '<!--' + wholeMatch + '-->';
};
}
return '<a id="' + m1 + m2 + '">' + '[' + m1 + ':' + m2 + ']' + '</a>';
});
//REFERENCES
var text = text.replace(/\\ref{(\S+):(\S+)}/g, function(wholeMatch, m1, m2) {
m2 = m2.replace(/<[/]?em>/g, "_");
if (conversion_to_html) {
if (m1 == "eq") return wholeMatch;
} else {
if (m1 == "eq") {
if (eqLabelWithNumbers) {
return eqLabNums[m2];
} else return m1 + ':' + m2;
}
}
return '<a class="latex_ref" href="#' + m1 + m2 + '">' + '[' + m1 + ':' + m2 + ']' + '</a>';
});
{
text = EnvReplace(text);
// LaTeX commands replacements (eg \textbf, \texit, etc)
var text = text.replace(/\\([\w]*){(.+?)}/g, function(wholeMatch, m1, m2) {
var cmd = cmdsMap[m1];
if (!cmd) return wholeMatch;
var tag = cmd.replacement;
return '<' + tag + '>' + m2 + '</' + tag + '>';
});
//Other small replacements
var text = text.replace(/\\index{(.+?)}/g, function(wholeMatch, m1) {
return '';
});
var text = text.replace(/\\noindent/g, "");
var text = text.replace(/\\(?:<\/p>)/g, "</p>");
};
};
//insert back listings in the text
text = text.replace(/!@!Listing(\d+)!@!/gm, function(wholeMatch, n) {
return '<pre>' + listings[n-1] + '</pre>';
});
return text;
};