Можно ли использовать веб-интерфейс jupyter notebook с пользовательскими шаблонами? - PullRequest
0 голосов
/ 25 октября 2018

Я видел много сообщений о том, как использовать пользовательский шаблон при рендеринге LaTeX из блокнота jupyter (например, скрыть код в блокноте jupyter ) и успешно реализовал ответ, описанный здесь ( пользовательский шаблонlocation ) Например:

~/dev/notebooks$ jupyter nbconvert --to=latex filename.ipynb --Application.log_level='DEBUG'

работает нормально (и применяет пользовательский шаблон, указанный в моем ~/.jupyter/jupyter_nbconvert_config.py).

Но как я могу настроить веб-интерфейс jupyter для работытаким же образом, используя:

File-> Download as-> LaTeX (.tex)

Заранее спасибо.

1 Ответ

0 голосов
/ 01 ноября 2018

Я нашел решение jupyter_notebook_config.py .По сути, приложение jupyter определяет применяемый шаблон, поэтому он прекрасно работал с:

jupyter nbconvert ...

, но не работал с:

File-> Download as->LaTeX (.tex)

Итак, используя этот ~ / .jupyter / jupyter_notebook_config.py:

import os

c = get_config()

c.TemplateExporter.template_path = [os.path.expanduser('~/.jupyter/templates'), \
'/usr/local/bin/miniconda3/envs/MyEnv/lib/python3.6/site-\
packages/jupyter_contrib_nbextensions/templates', '.']
c.LatexExporter.template_file = 'custom_latex.tplx'

и поместив файл custom_latex.tplx в каталог базовых шаблонов,Я могу установить шаблон по умолчанию (который ничего не делает), и тогда каждый пользователь может переопределить этот шаблон по умолчанию, как они выбирают (это для установки концентратора jupyter).Если вам не нужно это общее поведение (т. Е. Вы не находитесь в концентраторе jupyter), вы можете полностью игнорировать часть шаблона по умолчанию.

Для полноты ...

шаблон по умолчанию:

((= Nbconvert custom style for LaTeX export =))

((*- extends 'article.tplx' -*))

%==============================================================================\
=
% Custom definitions
%==============================================================================\
=
((* block definitions *))
    ((( super() )))

    % Pygments definitions
    ((( resources.latex.pygments_definitions )))

    % Exact colors from NB
    \definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
    \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}

    % Don't number sections
    \renewcommand{\thesection}{\hspace*{-0.5em}}
    \renewcommand{\thesubsection}{\hspace*{-0.5em}}

((* endblock definitions *))

% No title
((* block maketitle *))((* endblock maketitle *))



%==============================================================================\
=
% Latex Article
%==============================================================================\
=
% You can customize your LaTeX document here, e.g. you can
% - use a different documentclass like
%   \documentclass{report}
% - add/remove packages (like ngerman)

((* block docclass *))
% !TeX spellcheck = de_DE
% !TeX encoding = UTF-8
\documentclass{article}
((* endblock docclass *))

личный шаблон:

((= Nbconvert custom style for LaTeX export =))

((*- extends 'nbextensions.tplx' -*))

%==============================================================================\
=
% Custom definitions
%==============================================================================\
=
((* block definitions *))
    ((( super() )))

    % Pygments definitions
    ((( resources.latex.pygments_definitions )))

    % Exact colors from NB
    \definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
    \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}

    % Don't number sections
    \renewcommand{\thesection}{\hspace*{-0.5em}}
    \renewcommand{\thesubsection}{\hspace*{-0.5em}}

((* endblock definitions *))

% No title
((* block maketitle *))((* endblock maketitle *))



%==============================================================================\
=
% Latex Article
%==============================================================================\
=
% You can customize your LaTeX document here, e.g. you can
% - use a different documentclass like
%   \documentclass{report}
% - add/remove packages (like ngerman)

((* block docclass *))
% !TeX spellcheck = de_DE
% !TeX encoding = UTF-8
\documentclass{article}
% this is all unnecessary when extending nbextensions.tplx + hide_input_all
\usepackage{verbatim} %for {comment}
\usepackage{fancyvrb}
\renewenvironment{Verbatim}{\comment}{\endcomment}
((* endblock docclass *))

Надеюсь, это поможет кому-то еще - я не думаю, что документация ясна по этому вопросу вообще.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...