Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tikz externalization on Overleaf #70

Merged
merged 7 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ SJTUBeamer 是上海交通大学的非官方 Beamer 模版。您可以使用 SJT
% shadow tree smoothtree
% *siderbar 推荐与 max 一起使用。

% \tikzexternalize[prefix=cache/]
% 如果您需要缓存 tikz 图像,请取消注释上一行,并在编译选项中添加 -shell-escape。

\usepackage[backend=biber,style=gb7714-2015]{biblatex}
\addbibresource{thesis.bib}

Expand Down
3 changes: 3 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Current document `main.tex` is an example documentation of *How to Use LaTeX to
% shadow tree smoothtree
% *siderbar is recommended to be used with max option.

% \tikzexternalize[prefix=cache/]
% To cache the tikz picture, please uncomment the previous line.

\usepackage{biblatex}
\addbibresource{thesis.bib}

Expand Down
2 changes: 1 addition & 1 deletion beamercolorthemesjtubeamer.sty

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion beamerfontthemesjtubeamer.sty

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion beamerinnerthemesjtubeamer.sty

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion beamerouterthemesjtubeamer.sty

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion beamerthemesjtubeamer.sty

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added cache/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
% shadow tree smoothtree
% *siderbar 推荐与 max 一起使用。

% \tikzexternalize[prefix=cache/]
% 如果您需要缓存 tikz 图像,请取消注释上一行,并在编译选项中添加 -shell-escape。

\author{Alexara Wu}
\institute[SJTUG]{上海交通大学 Linux 用户组}
\date{\the\year 年 \the\month 月}
Expand Down
2 changes: 1 addition & 1 deletion sjtucover.sty

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions sjtuvi.sty

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ else
typesetexe = "xelatex"
end

typesetopts = "-interaction=nonstopmode -shell-escape"
typesetfiles = {"sjtubeamerdevguide.tex","sjtubeamer.tex"}
-- typesetfiles = {"sjtubeamer.tex"}
-- typesetruns = 1 -- for debug. Some reference may not be linked.
Expand Down
13 changes: 11 additions & 2 deletions src/doc/sjtubeamer.tex
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,17 @@ \section{统计图}

\begin{enumerate}\small
\item 需要加载 \texttt{pgfplots} 宏包,必要时额外加载 \texttt{pgfplotstable} 宏包以读取文件数据。可以使用 \href{https://logcreative.github.io/PGFPlotsEdt/}{PGFPlots 统计绘图编辑器} 生成上述代码。
\item[\faExclamationTriangle] 过多的统计图会增长编译时间,不宜过多使用。
\item[\faInfoCircle] 现在的版本对于 Ti\emph{k}Z 插图有实验性的优化,当编译采用 \verb"--shell-escape" 开关时,会启动缓存模式。第一次编译时因为需要渲染缓存会稍慢,但是后面的编译都将使用这次编译的产物,就如直接添加图片一样,就会变得快起来。
\end{enumerate}

\section{缓存}

如果你需要使用较多的 Ti\emph{k}Z 和 \texttt{pgfplots} 插图,可以考虑启用图像缓存,当图像没有被更改时会采用上一次的编译产物。\themename\ 已经保护了一些不必要缓存的元素。

\beamerdemo[1]{stepcache.tex}

\begin{enumerate}
\item \themename\ 已经加载了 \verb"\usetikzlibrary{external}"。
\item[\faExclamationTriangle] 如果使用的是 Overleaf 这种在线 \LaTeX\ 编译器,您必须要在主文档内使用 \verb"\tikzexternalize[prefix=cache/]" 命令,并且要在同级目录下新建 \verb"cache/" 文件夹,其中应该还有一个占位文档(比如 \verb".gitkeep")。可参见 \href{https://www.overleaf.com/learn/latex/Questions/I_have_a_lot_of_tikz%2C_matlab2tikz_or_pgfplots_figures%2C_so_I%27m_getting_a_compilation_timeout._Can_I_externalise_my_figures%3F}{相关说明}。
\end{enumerate}

% TODO: 以后的开发计划:Smart Diagram
Expand Down
2 changes: 1 addition & 1 deletion src/source/beamercolorthemesjtubeamer.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamercolorthemesjtubeamer}[2021/10/02 sjtubeamer color theme v2.2.2]
\ProvidesPackage{beamercolorthemesjtubeamer}[2021/10/05 sjtubeamer color theme v2.2.3]
%</package>
% \fi
% \CheckSum{0}
Expand Down
2 changes: 1 addition & 1 deletion src/source/beamerfontthemesjtubeamer.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerfontthemesjtubeamer}[2021/10/02 sjtubeamer font theme v2.2.2]
\ProvidesPackage{beamerfontthemesjtubeamer}[2021/10/05 sjtubeamer font theme v2.2.3]
%</package>
% \fi
% \CheckSum{0}
Expand Down
2 changes: 1 addition & 1 deletion src/source/beamerinnerthemesjtubeamer.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerinnerthemesjtubeamer}[2021/10/02 sjtubeamer inner theme v2.2.2]
\ProvidesPackage{beamerinnerthemesjtubeamer}[2021/10/05 sjtubeamer inner theme v2.2.3]
%</package>
% \fi
% \CheckSum{0}
Expand Down
2 changes: 1 addition & 1 deletion src/source/beamerouterthemesjtubeamer.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerouterthemesjtubeamer}[2021/10/02 sjtubeamer outer theme v2.2.2]
\ProvidesPackage{beamerouterthemesjtubeamer}[2021/10/05 sjtubeamer outer theme v2.2.3]
%</package>
% \fi
% \CheckSum{0}
Expand Down
2 changes: 1 addition & 1 deletion src/source/beamerthemesjtubeamer.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
% ------------------------------------------------------------------- \fi
% \iffalse
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerthemesjtubeamer}[2021/10/02 sjtubeamer parent theme v2.2.2]
\ProvidesPackage{beamerthemesjtubeamer}[2021/10/05 sjtubeamer parent theme v2.2.3]
% \fi
%
% \subsection{Parent Theme}
Expand Down
2 changes: 1 addition & 1 deletion src/source/sjtucover.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{sjtucover}[2021/10/02 cover library for sjtubeamer v2.2.2]
\ProvidesPackage{sjtucover}[2021/10/05 cover library for sjtubeamer v2.2.3]
%</package>
% \fi
% \CheckSum{0}
Expand Down
18 changes: 3 additions & 15 deletions src/source/sjtuvi.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{sjtuvi}[2021/10/02 Visual Identity System library for sjtubeamer v2.2.2]
\ProvidesPackage{sjtuvi}[2021/10/05 Visual Identity System library for sjtubeamer v2.2.3]
%</package>
% \fi
% \CheckSum{0}
Expand Down Expand Up @@ -119,7 +119,8 @@
\fi
\expandafter\providecommand\csname #1\endcsname[1][\sjtubeamer@logocolor]{
% ##1: override color, or opacity=... (optional)
\begin{tikzpicture}[external/export=false]
\tikzexternaldisable
\begin{tikzpicture}
\begin{scope}
\clip ({-1.0+#2},{-1.0+#3}) rectangle ({1.0-#2},{1.0-#3});
\fill [\sjtubeamer@logocolor, ##1, path fading=#1]
Expand Down Expand Up @@ -257,19 +258,6 @@
% \end{macrocode}
% \end{macro}
%
% Provides the command for deciding if it is in --shell-escape mode.
% \begin{macrocode}
\RequirePackage{pdftexcmds}
% \end{macrocode}
% Enable the externalization and cache all pdf's to \verb"cache/" folder, if it is in --shell-escape mode (1).
% NOTICE: the externalization starts from the end of preamble to avoid the conflict with the \verb"fadings" library.
% \begin{macrocode}
\ifnum\pdf@shellescape=1
\AtEndPreamble{
\tikzexternalize[prefix=cache/]
}
\fi
% \end{macrocode}
%
% \iffalse
%</package>
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions src/support/tutorial/stepcache.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
\documentclass{ctexbeamer}
\usetheme{sjtubeamer}
\usetikzlibrary{math}
\tikzexternalize[prefix=cache/]
\begin{document}
\begin{frame}
\frametitle{缓存插图}
\begin{tikzpicture}[scale=0.7]
\foreach \x in {1,...,7}{
\foreach \y in {\x,...,7}{
\draw (\x,\y-1)--(\x,\y);
\draw (\x+1,\y)--(\x,\y);
}
}
\foreach \x in {1,...,8}{
\pgfmathparse{int(\x-1)}
\foreach \y in {\pgfmathresult,...,7}{
\node[draw,circle,fill=white,scale=0.6]
at (\x,\y) {\x,\y};
}
}
\end{tikzpicture}
\end{frame}
\end{document}