Skip to content

Instantly share code, notes, and snippets.

@ssh0
Last active November 6, 2015 11:20
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 ssh0/af3decc647a24bb562e4 to your computer and use it in GitHub Desktop.
Save ssh0/af3decc647a24bb562e4 to your computer and use it in GitHub Desktop.
プレゼンで使う数式画像を作成する[vim + vim-quickrun + latexmk + dvipng] ref: http://qiita.com/ssh0/items/2113db858ba5c9fd05df
#!/usr/bin/perl
$latex = 'platex -interaction=nonstopmode -kanji=utf-8 %O %S';
$pdf_mode = 0;
augroup texmath
autocmd!
autocmd FileType texmath setlocal syntax=tex
augroup END
\documentclass[43pt]{jsarticle}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{ascmac}
\pagestyle{empty}
% "\vector{a}" でベクトル
\def\vector#1{\mbox{\boldmath \(#1\)}}
\begin{document}
\begin{align*}
f(x) &= \int^{\infty}_{-\infty}\mathrm{d}x \frac{\sin x}{x} \\
&= \pi
\end{align*}
\newpage
$\vector{x} = (x_{1}, x_{2})$
\newpage
$\mathcal{C}$
\end{document}
platex fig_test.tex
dvipng -T tight -bd 1000 fig_test.dvi
texmath fig_test.tex
\documentclass[43pt]{jsarticle}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{ascmac}
\pagestyle{empty}
% "\vector{a}" でベクトル
\def\vector#1{\mbox{\boldmath \(#1\)}}
\begin{document}
\end{document}
" LaTeX Quickrun (texmath)
let g:quickrun_config['texmath'] = {
\ 'runner' : 'vimproc',
\ 'command' : 'texmath',
\ 'outputter' : 'error',
\ 'outputter/error/success' : 'null',
\ 'outputter/error/error' : 'quickfix',
\ 'srcfile' : expand("%s"),
\ 'exec': '%c %s',
\}
augroup latex_autocompile
autocmd!
if g:quickrun_user_tex_autorun != 0
autocmd BufWritePost,FileWritePost *.tex :QuickRun
autocmd BufWritePost,FileWritePost fig*.tex :QuickRun -type texmath
endif
augroup END
#!/bin/bash -e
# written by Shotaro Fujimoto (https://github.com/ssh0)
# first edited: 2015-11-03
# using latexmk rc file
latexmkrc="$HOME/.latexmkrc_dvipng"
usage() {
cat <<EOF
NAME
texmath - compile latex to png with dvipng (and create texmath file)
USAGE
texmath [-e FILE | FILE] [-h]
ARGUMENTS
-e FILE: Open and edit FILE.
Or create it when FILE doesn't exist,
FILE: If you provide only file name, this script compiles the file with
latexmk and then creates png file by dvipng.
--help: Display this help and exit
EOF
exit 1
}
texmathtemplate="$(cat <<EOF
% vim: ft=texmath
\documentclass[43pt]{jsarticle}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{ascmac}
\pagestyle{empty}
% '\vector{a}' でベクトル
\def\vector#1{\mbox{\boldmath \(#1\)}}
\begin{document}
\begin{eqnarray*}
\end{eqnarray*}
\newpage
\end{document}
EOF
)"
if [ "$1" = "-h" ]; then
usage
elif [ "$1" = "-e" ]; then
if [ -f "$2" ]; then
texfile="$2"
elif [ ! "$2" = "" ]; then
texfile="$2"
echo "$texmathtemplate" > "$texfile"
else
echo "Option '-e' needs a file name to edit."
echo "Aborted."
exit 1
fi
vim "$texfile"
elif [ ! -f "$1" ]; then
echo "'$1' doesn't exist."
echo "Aborted."
exit 1
elif [ -f "$1" ]; then
texfile="$1"
latexmk -r "$latexmkrc" "${texfile}" \
&& latexmk -c "${texfile}" \
&& dvipng -T tight -bd 1000 "${texfile%.tex}.dvi" \
&& rm *.fls
else
usage
fi
" LaTeX Quickrun (texmath)
let g:quickrun_config['texmath'] = {
\ 'runner' : 'vimproc',
\ 'command' : 'texmath',
\ 'outputter' : 'error',
\ 'outputter/error/success' : 'null',
\ 'outputter/error/error' : 'quickfix',
\ 'srcfile' : expand("%s"),
\ 'exec': '%c %s',
\}
augroup texmath_autocompile
autocmd!
autocmd BufWritePost,FileWritePost *.tex :QuickRun
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment