Leun Kim's BlogWindy Odaiba

Others / Blog Tips

[Plugin] Adding QuickLaTeX to My Blog (TikZ Graphs and Diagrams)

Blog TipsOthers2 comments

Translated from the Korean original. Read the original →

I've added QuickLaTeX to my blog. Its big selling point is that it renders TikZ code as images. It handles regular equations too, but since I'm already using MathJax for those, I'll probably only use it for graphs and figures (not that I expect to be drawing many graphs, honestly).

Download the QuickLaTeX plugin: http://www.holoborodko.com/pavel/quicklatex

Here are a few simple examples made with QuickLaTeX. Since the code would otherwise get rendered automatically, I've left out the \ in front of begin.

begin{tikzpicture}
[+preamble]
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
[/preamble]
\begin{axis}
\addplot3[surf,domain=0:360,samples=60] {cos(x)*cos(y)};
\end{axis}
\end{tikzpicture}

Type that in, and it renders like this:

\begin{tikzpicture} [+preamble] \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} [/preamble] \begin{axis} \addplot3[surf,domain=0:360,samples=60] {cos(x)*cos(y)}; \end{axis} \end{tikzpicture}

f(x,y) = \cos x \cos y

If rendering feels a bit slow, you can lower the number of samples like this:

begin{tikzpicture}
[+preamble]
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
[/preamble]
\begin{axis}
\addplot3[surf,domain=0:360,samples=20] {sin(x)*sin(y)};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture} [+preamble] \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} [/preamble] \begin{axis} \addplot3[surf,domain=0:360,samples=20] {sin(x)*sin(y)}; \end{axis} \end{tikzpicture}
f(x,y) = \sin x \sin y

You can also create all sorts of other figures like these right on the web page.

begin{tikzpicture}
[+preamble]
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
[/preamble]
\begin{axis}[xlabel=Time (weeks),ylabel=Individuals,
width=12cm,height=6cm
]
\addplot coordinates {(1,8) (2,9) (4,7) (5,13)
(6,12) (8,18) (9,17) (10,22) (11,41) (12,32)
(13,24) (14,21) (16,21.5) (21,19.4) (25,21.02)};
\node[coordinate,pin={below:{Control}}] at (axis cs:16,21.5) {};
\addplot coordinates {(1,4) (2,3) (4,5) (5,7)
(6,9) (7,8) (8,12) (9,23) (10,38) (11,34)
(12,35) (13,33.2) (14,27) (16,25) (21,24.4) (25,24.9)};
\node[coordinate,pin={above:{Treatment}}] at (axis cs:21,24.4) {};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture} [+preamble] \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} [/preamble] \begin{axis}[xlabel=Time (weeks),ylabel=Individuals, width=12cm,height=6cm ] \addplot coordinates {(1,8) (2,9) (4,7) (5,13) (6,12) (8,18) (9,17) (10,22) (11,41) (12,32) (13,24) (14,21) (16,21.5) (21,19.4) (25,21.02)}; \node[coordinate,pin={below:{Control}}] at (axis cs:16,21.5) {}; \addplot coordinates {(1,4) (2,3) (4,5) (5,7) (6,9) (7,8) (8,12) (9,23) (10,38) (11,34) (12,35) (13,33.2) (14,27) (16,25) (21,24.4) (25,24.9)}; \node[coordinate,pin={above:{Treatment}}] at (axis cs:21,24.4) {}; \end{axis} \end{tikzpicture}

 

begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
thick,main node/.style={circle,fill=red!20,draw,font=\sffamily\Large\bfseries}]
[+preamble]
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows}
[/preamble]
\node[main node] (1) {A};
\node[main node] (2) [below left of=1] {B};
\node[main node] (3) [below right of=2] {C};
\node[main node] (4) [below right of=1] {D};
\path[every node/.style={font=\sffamily\small}]
(1) edge node [left] {a} (4)
edge [bend right] node[left] {b} (2)
edge [loop above] node {c} (1)
(2) edge node [right] {d} (1)
edge node {0.1} (4)
edge [loop left] node {100} (2)
edge [bend right] node[left] {20} (3)
(3) edge node [right] {0.04} (2)
edge [bend right] node[right] {40} (4)
edge [loop below] node {1} (3)
(4) edge node [left] {e} (3)
edge [loop right] node {f} (4)
edge [bend right] node[right] {g} (1);
\end{tikzpicture}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm, thick,main node/.style={circle,fill=red!20,draw,font=\sffamily\Large\bfseries}] [+preamble] \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{arrows} [/preamble] \node[main node] (1) {A}; \node[main node] (2) [below left of=1] {B}; \node[main node] (3) [below right of=2] {C}; \node[main node] (4) [below right of=1] {D}; \path[every node/.style={font=\sffamily\small}] (1) edge node [left] {a} (4) edge [bend right] node[left] {b} (2) edge [loop above] node {c} (1) (2) edge node [right] {d} (1) edge node {0.1} (4) edge [loop left] node {100} (2) edge [bend right] node[left] {20} (3) (3) edge node [right] {0.04} (2) edge [bend right] node[right] {40} (4) edge [loop below] node {1} (3) (4) edge node [left] {e} (3) edge [loop right] node {f} (4) edge [bend right] node[right] {g} (1); \end{tikzpicture}

 

[+preamble]
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{gnuplot]
[/preamble]
begin{tikzpicture}[scale=2]
\shade[top color=red,bottom color=gray!50]
(0,0) parabola (1.5,2.25) |- (0,0);
\draw (1.05cm,2pt) node[above]
{$\displaystyle\int_0^{3/2} \!\!x^2\mathrm{d}x$};
\draw[style=help lines] (0,0) grid (3.9,3.9)
[step=0.25cm] (1,2) grid +(1,1);
\draw[->] (-0.2,0) -- (4,0) node[right] {$x$};
\draw[->] (0,-0.2) -- (0,4) node[above] {$f(x)$};
\foreach \x/\xtext in {1/1, 1.5/1\frac{1}{2}, 2/2, 3/3}
\draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
\foreach \y/\ytext in {1/1, 2/2, 2.25/2\frac{1}{4}, 3/3}
\draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};
\draw (-.5,.25) parabola bend (0,0) (2,4) node[below right] {$x^2$};
\end{tikzpicture}

[+preamble] \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{gnuplot] [/preamble] \begin{tikzpicture}[scale=2] \shade[top color=red,bottom color=gray!50] (0,0) parabola (1.5,2.25) |- (0,0); \draw (1.05cm,2pt) node[above] {$\displaystyle\int_0^{3/2} \!\!x^2\mathrm{d}x$}; \draw[style=help lines] (0,0) grid (3.9,3.9) [step=0.25cm] (1,2) grid +(1,1); \draw[->] (-0.2,0) -- (4,0) node[right] {$x$}; \draw[->] (0,-0.2) -- (0,4) node[above] {$f(x)$}; \foreach \x/\xtext in {1/1, 1.5/1\frac{1}{2}, 2/2, 3/3} \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$}; \foreach \y/\ytext in {1/1, 2/2, 2.25/2\frac{1}{4}, 3/3} \draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$}; \draw (-.5,.25) parabola bend (0,0) (2,4) node[below right] {$x^2$}; \end{tikzpicture}

You can find many more examples and their output at sites like http://www.texample.net/tikz/examples/all.

#QuickLatex#Tikz

More in Blog Tips

See all

Comments 2

  1. 파도소리

    안녕하세요. 지나가다 좋은 포스트를 읽게 되었네요.글에서는 QuickLaTex를 블로그에 적용시키셨다고 하셨는데 지금 수식을 보니 MathJax를 쓰고 계시더라구요. 다시 MathJax로 바꾸신 이유가 있을까요?

    1. Leun Kim

      안녕하세요. 사실 Quick LaTeX를 제거한 별다른 이유는 없어요. 모바일 환경에서 Quick LaTeX보다 MathJax가 조금 더 컴패티블하다고 판단해서 바꿨네요. Quick LaTeX같은 경우 모바일에서 긴 수식을 볼 때 그림 파일이라 짤리던지 아니면 그림 전체가 축소되어 폰트 크기가 들쭉날쭉 하게 되는데 반해 MathJax의 경우 적어도 그런 문제는 없어서 바꿨습니다.

    Leave a comment

    Your name and comment are shown on this page (private comments only to the blog owner). Your e-mail address is never shown.

    Back to top