%!TEX program = xelatex
%!TEX options = -shell-escape --file-line-error --synctex=1
\documentclass[
a4paper,xelatex,everyparhook=compat,
ja=standard,
oneside,
textwidth-limit=50,
]{bxjsbook}
\evensidemargin 0.0in
\oddsidemargin 0.0in
\usepackage{amsmath,amsthm}
\usepackage[
setpagesize=false,
bookmarksnumbered=true,%
bookmarksopen=true,%
colorlinks=true,%
linkcolor=blue,
citecolor=blue,
urlcolor=blue
]{hyperref}
%\usepackage{cleveref}
%\usepackage[plain]{fancyref}
%\usepackage{varioref}
\usepackage{cleveref}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{unicode-math}
%
%%-------
%% Typography
%%-------
%
\usepackage[]{fontenc}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{dsfont}
\usepackage{microtype}
\usepackage[onehalfspacing]{setspace}
%
%% 言語と日本語フォントの設定 (!!!!要インストール!!!!)
\setmonofont{Cica} % https://github.com/miiton/Cica
%% mac 環境ならbrewでinstall可能
%% $ brew tap brew tap homebrew/cask-fonts
%% $ brew install --cask font-cica
\setmainlanguage{japanese}
\setotherlanguage{english}
\newfontfamily\japanesefont{Hiragino Mincho Pro} % ヒラギノ明朝を使用
\newfontfamily\cjkfont{Hiragino Mincho Pro} % CJKフォント
\newfontfamily\cjkfontsf{Hiragino Sans W3}
%-------
% Notebook Styling
%-------
%
\usepackage[most,minted]{tcolorbox}
\tcbuselibrary{listings}
\tcbset{nobeforeafter}
\definecolor{outcolor}{HTML}{D84315}
\newlength{\promptwidth}
\setlength{\promptwidth}{30pt}
\newlength{\promptsep}
\setlength{\promptsep}{5.5pt}
\newlength{\promptshift}
\setlength{\promptshift}{5pt}
\newcommand{\prompt}[4]{%
\makebox[0pt][r]{\texttt{\color{#2}#1[#3]:#4}}\vspace{-\baselineskip}%
}
\newcommand{\pinref}[1]{\texttt{\color{outcolor}{In}[\ref{code:In-#1}]}}
\newcommand{\poutref}[1]{\texttt{\color{outcolor}{Out}[\ref{code:Out-#1}]}}
\newcounter{NBin}
\newcounter{NBout}
% NotebookOut 環境の定義
\newtcblisting{ipynbin}{
breakable,
boxrule=.5pt,
size=fbox,
left skip = \promptwidth + \promptsep,
pad at break*=1mm,
opacityfill=1,
phantom=\refstepcounter{NBin},
label=code:In-\theNBin,
title=\prompt{In}{outcolor}{\theNBin}{\hspace{\promptsep + \promptshift}},
% fonttitle=\linespread{2}\small,
attach title to upper,
listing only,
minted language=python, % mintedを使用
minted options={ % mintedのオプション設定
breaklines=true,
texcomments,
escapeinside=||,
mathescape=true,
linenos=true,
numbersep=10pt,
xleftmargin=5pt,
fontsize=\scriptsize,
},
}
\newtcblisting{ipynbout}{
breakable,
boxrule=.5pt,
size=fbox,
left skip = \promptwidth + \promptsep,
pad at break*=1mm,
opacityfill=1,
phantom=\refstepcounter{NBout},
label=code:Out-\theNBin,
title=\prompt{Out}{outcolor}{\theNBout}{\hspace{\promptsep + \promptshift}},
% fonttitle=\linespread{1}\small,
attach title to upper,
listing only,
minted language=python, % mintedを使用
minted options={ % mintedのオプション設定
breaklines=true,
escapeinside=||,
mathescape=true,
linenos=false,
numbersep=10pt,
xleftmargin=5pt,
fontsize=\scriptsize,
% bgcolor=LightGray,
},
}
\newtcolorbox{ipynbfigout}{
breakable,
boxrule=.5pt,
size=fbox,
left skip = \promptwidth + \promptsep,
pad at break*=1mm,
opacityfill=1,
phantom=\refstepcounter{NBout},
label=code:Out-\theNBout,
% title=\prompt{Out}{outcolor}{\theNBout}{\hspace{\promptsep}},
% fonttitle=\linespread{1}\small,
attach title to upper,
enhanced,
overlay={
\node[anchor=south west, font=\normalfont, yshift=-2ex, xshift = - \promptshift] at (frame.north west) {\prompt{Out}{outcolor}{\theNBout}{\hspace{\promptsep}}};
},
}
\usepackage{mathrsfs}
\usepackage{centernot}
\usepackage{bm}
\usepackage{xcolor}
\usepackage{xifthen} % 条件分岐のためのパッケージ
\usepackage{float}
\usepackage{subcaption}
\usepackage[]{derivative} % 微分パッケージ
\usepackage{chapterbib}
\usepackage[authoryear,numbers]{natbib}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage[]{subcaption}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%
% mintedの設定 ソースコード用
\usepackage{float}
\usepackage{caption}
%
%% 新しい code 環境を定義して、captionを設定
%
%\definecolor{LightGray}{gray}{0.9}
\usepackage{minted}
%%\usemintedstyle{sas} % minted の style $ pygmentize -L styles で利用可能なstyleが表示される.
\usemintedstyle{igor}
%%%
% 日本語でminedを使うためにpython pakageのpygmentizeをtexbinにパスを通す必要があるかも?.
% $ sudo ln -s `which pygmentize` /Library/TeX/texbin
%%
%\setminted{
% breaklines=true,
% escapeinside=||,
% mathescape=true,
% xleftmargin=5pt,
% linenos=false,
% fontsize=\scriptsize,
% bgcolor=black,
% formatcom=\color{white},
%% bgcolor=LightGray,
%}
\begin{document}
\href{https://tex.stackexchange.com/questions/521607/jupyter-in-out-without-overflowing?newreg=8110a09c2b6c45feb2eeb22bba32ccf6}{stackexchange (jupyter in out without overflowing) } を参考に,jupyter notebookのようなstyleにしてみた.
\begin{ipynbin}
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
ŷ,d̂,ȳ, ŷ₁ #一部の文字の合字が正しく表示できないようだ.
A = [3, 6, 1, 3, 5, 10, 3, 2, 7, 2, 5, 8, 7, 6, 1, 8, 4, 5, 4, 0, 9, 3, 4]
B = [8, 5, 4, 3, 5, 7, 6, 4, 3, 5, 4, 4, 5, 3, 4, 6, 4, 5, 5, 6, 3, 7, 2]
β₀ = 2; β₁ = 3.0; X = -2:2
df = pd.DataFrame({
'試験A': A,
'試験B': B,
})
\end{ipynbin}
\begin{ipynbout}
print( sorted( df["試験A"] )) bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa
print( sorted( df["試験B"] ))
β₀ = 2; β₁ = 3.0; X = -2:2
ŷ = predict(lr_res) | $\mid $の内側はescapeされTeX文章として認識される$\mid$|
\end{ipynbout}
\begin{ipynbfigout}
\begin{tikzpicture}
\begin{axis}[width=5cm]
\addplot[domain=-5:5,smooth,very thick] {exp(-x^2/2)};
\end{axis}
\end{tikzpicture}%
\end{ipynbfigout}
\begin{align}
\sqrt{1,2,3,4,4,6}
\end{align}
\begin{minted}[
fontsize=\scriptsize,
bgcolor=black,
formatcom=\color{white},
]{bash}
$ echo Hello World
\end{minted}
\pinref{1},\poutref{1},\poutref{2}
\end{document}