Skip to content

Instantly share code, notes, and snippets.

@hidaruma
Last active July 5, 2019 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidaruma/fe44e759f93ac276435814d2b99410a9 to your computer and use it in GitHub Desktop.
Save hidaruma/fe44e759f93ac276435814d2b99410a9 to your computer and use it in GitHub Desktop.
Sphinx LaTeX modify stylefile.
% sphinx-jsbook-mod.sty
%
% by hidaruma <hidaruma@outlook.jp>
%
% Please load after sphinx.sty. Cause this sty using some macros in sphinx.sty
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sphinx-jsbook-mod}[2019/07/05 v0.0.1 LaTeX package (Sphinx markup)]
% In 2019, jsbook has defined \plainifnotempty.
% This command is used in \chapter command,
% and it overwrites chapter page from sphinx manual pagestyle.
% Following codes overwrite \plainifnotempty.
\@ifpackageloaded{fancyhdr}{%
\ltx@ifundefined{c@chapter}{%
}{%
\fancypagestyle{chapterfoot}{%
\fancyhf{}%
\fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}%
\fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}%
\fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}%
\renewcommand\headrulewidth{0pt}%
}
}
}%
\ifdefined\plainifnotempty %
\@ifpackageloaded{fancyhdr}{%
\renewcommand{\plainifnotempty}{%
\ltx@ifundefined{c@chapter}{%
}{%
\ifx \@oddhead \@empty%
\ifx \@oddfoot \@empty%
\else%
\thispagestyle{chapterfoot}%
\fi%
\else%
\thispagestyle{chapterfoot}%
\fi}%
}%
}%
\fi%
@hidaruma
Copy link
Author

hidaruma commented Jul 5, 2019

スタイルファイル名はjsbookでしか検証していないため暫定。多分日本語(jsclasses)環境でしか起きないしPR出すかは判断がつかない。
Sphinxでjsbookをロードしたクラスファイルを使ったとき、章題ページのページ番号位置が微妙だったので他のページによせる処理をします。

コピーして、conf.pyの
latex_additional_files でビルド時コピーできる場所に置いて設定し、

latex_elements = { 'preamble': '''
\\usepackage{sphinx-jsbook-mod}
'''}

としましょう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment