
我想轉換一段簡單的 LaTeX 程式碼,它基本上是一些文本,中間有一些居中的圖形。這是我想要轉換為 HTML 的程式碼的虛擬版本:
\documentclass{article}
\usepackage{lmodern}
\usepackage{pgfplots}
\usepackage{lipsum}
\pgfplotsset{compat=1.9}
\begin{document}
\lipsum
\begin{center}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
ymin=0, ymax=35,
width=9cm,
height=6cm,
symbolic x coords={Zimbabwe, France, Italy, Kenya, Germany},
xtick=data,
bar width=15pt,
axis lines*=left,
ytick={0,5,...,35},
xticklabel style={
text height=1.5ex,font=\footnotesize
},
yticklabel style={
font=\footnotesize
},
ymajorgrids,
xlabel={ ... ... ... ... ... , 2004-2009},
xlabel style={yshift=5.8cm,xshift=.9cm},
]
\addplot[fill=gray!50] coordinates {
(Zimbabwe,16)
(France,30)
(Italy,10)
(Kenya,5)
(Germany,20)
};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
我厭倦了latex4ht
我過去使用過的 ,但它似乎不適用於 PGFplot 代碼。
所以我的問題是:如何將 PGFplot 圖表轉換為 html?感謝您的協助
答案1
有很多方法可以使用tikz
和取得 html 和 svg 圖形tex4ht
。在我看來,最好的方法是使用tikz externalization
函式庫來進行轉換。使用這個庫,pdf
可以為每張圖片創建獨立的圖像,然後可以使用一些外部命令將該圖像tikz
轉換為.我在這項工作和其他應用程式中取得了巨大成功,就像我發現了一些問題並且結果不正確。因此,您需要安裝才能使其正常工作。pdf
svg
inkscape
imagemagick
inkscape
externalization
首先,創建將為我們設定的套件myexternalize.sty
:
\usetikzlibrary{external}
\tikzset{
tex4ht inc/.style={
/pgf/images/include external/.code={%
\includegraphics[]{##1.svg}%
}
}
}
\tikzset{
external/system call/.add={}
{; inkscape -z -f "\image.pdf" -l "\image.svg"
}
}
\@ifpackageloaded{tex4ht}{
\tikzexternalize[mode=only graphics]
\tikzset{tex4ht inc}
}{
\tikzexternalize
}
該包創建了新tikz
樣式tex4ht inc
,它將與 一起使用tex4ht
。使用pdflatex
,pdf
文件將被導出並inscape
在命令行模式下調用以將此pdf
圖像轉換為svg
.
現在我們需要一些配置tex4ht
,以便能夠包含svg
圖像、檔案myexternalize.4ht
:
\Configure{graphics*}
{svg}{
{\Configure{Needs}{File: \[email protected]}\Needs{}}
\Picture[\csname a:GraphicsAlt\endcsname]{\csname Gin@base\endcsname.svg \csname a:Gin-dim\endcsname}%
}
現在您可以myexternalize
在文件中包含套件:
\documentclass{article}
\usepackage{lmodern}
\usepackage{pgfplots}
\usepackage{lipsum}
\pgfplotsset{compat=1.9}
\usepackage{myexternalize}
....
然後編譯文檔
pdflatex -shell-escape documentname
獲取svg
文件。-shell-escape
選項很重要,否則轉換無法進行!現在你可以將檔案編譯為 html:
htlatex documentname
你可以看到結果這裡