Skip to content

Instantly share code, notes, and snippets.

@ssh0
Created July 1, 2015 13:38
Show Gist options
  • Save ssh0/6215066fca8544bd7542 to your computer and use it in GitHub Desktop.
Save ssh0/6215066fca8544bd7542 to your computer and use it in GitHub Desktop.
TeXをもっと便利に使う!(自動コンパイル・部分コンパイル・分割ファイルから親ファイルのコンパイル)【Vim + vim-quickrun + latexmk】 ref: http://qiita.com/ssh0/items/e6d7540cd46fac580bc2
#!/usr/bin/perl
$latex = 'platex -interaction=nonstopmode -kanji=utf-8 %O %S';
$dvipdf = 'dvipdfmx %O -o %D %S';
$bibtex = 'pbibtex';
$pdf_mode = 3; # use dvipdf
$pdf_update_method = 2;
$pdf_previewer = "start mupdf %O %S";
# Prevent latexmk from removing PDF after typeset.
# $pvc_view_file_via_temporary = 0;
#!/bin/sh
# written by Shotaro Fujimoto (https://github.com/ssh0)
# first edited: 2015-06-26
# If there is a file named below in the same directory,
# this script automatically detect that the file is root tex file,
# and compile this file even if you choose different one.
rootfile='main.tex'
# If the choosed file is in $sourcedir, default outputdir is setted to one
# level upper directory.
sourcedir='source'
message() {
echo "There is$1 '$rootfile' in the directory '$2',"
echo "so this script compiles this file."
echo ""
}
search_rootfile() {
if [ -f "$1"/"$rootfile" ]; then
texfile="$1"/"$rootfile"
message "" "$1"
return 0
else
texfile="$1"/"$name"
return 1
fi
}
dir="$(cd "$(dirname $1)"; pwd)"
name="$(basename $1)"
if [ ! -f "$dir/$name" ]; then
echo "$dir/$name doesn't exist."
exit 1
fi
currentdir="$(basename $dir)"
dir_up="$(dirname $dir)"
if [ ${currentdir} = $sourcedir ]; then
echo "This file is in '$sourcedir', so search '$rootfile' recursively."
outdir="${dir_up}"
search_rootfile ${dir_up} || search_rootfile $dir || message " not" "$dir"
else
outdir="$dir"
search_rootfile $dir || message " not" "$dir"
fi
echo "Run latexmk..."
echo "============"
echo ""
shift 1
latexmk -pdfdvi -output-directory=$outdir "$@" $texfile
sudo chmod u+x ~/bin/latexmk_wrapper
" Plugin (managed by NeoBundle)
"==============================
" for LaTeX
NeoBundle 'lervag/vimtex'
let g:vimtex_fold_envs = 0
let g:vimtex_view_general_viewer = 'mupdf'
" vim-quickrun
NeoBundle 'thinca/vim-quickrun'
" autocmd
"==============================
augroup filetype
autocmd!
" tex file (I always use latex)
autocmd BufRead,BufNewFile *.tex set filetype=tex
augroup END
" disable the conceal function
let g:tex_conceal=''
" LaTeX Quickrun
let g:quickrun_config['tex'] = {
\ 'command' : 'latexmk_wrapper',
\ 'outputter' : 'error',
\ 'outputter/error/success' : 'null',
\ 'outputter/error/error' : 'quickfix',
\ 'srcfile' : expand("%s"),
\ 'exec': '%c %s %a %o',
\}
" 部分的に選択してコンパイル
" http://auewe.hatenablog.com/entry/2013/12/25/033416 を参考に
let g:quickrun_config.tmptex = {
\ 'exec': [
\ 'mv %s %a/tmptex.latex',
\ 'latexmk -pdfdvi -pv -output-directory=%a %a/tmptex.latex',
\ ],
\ 'args' : expand("%:p:h:gs?\\\\?/?"),
\ 'outputter' : 'error',
\ 'outputter/error/error' : 'quickfix',
\
\ 'hook/eval/enable' : 1,
\ 'hook/eval/cd' : "%s:r",
\
\ 'hook/eval/template' : '\documentclass{jsarticle}'
\ .'\usepackage[dvipdfmx]{graphicx, hyperref}'
\ .'\usepackage{float}'
\ .'\usepackage{amsmath,amssymb,amsthm,ascmac,mathrsfs}'
\ .'\allowdisplaybreaks[1]'
\ .'\theoremstyle{definition}'
\ .'\newtheorem{theorem}{定理}'
\ .'\newtheorem*{theorem*}{定理}'
\ .'\newtheorem{definition}[theorem]{定義}'
\ .'\newtheorem*{definition*}{定義}'
\ .'\renewcommand\vector[1]{\mbox{\boldmath{\(#1\)}} }'
\ .'\begin{document}'
\ .'%s'
\ .'\end{document}',
\
\ 'hook/sweep/files' : [
\ '%a/tmptex.aux',
\ '%a/tmptex.dvi',
\ '%a/tmptex.fdb_latexmk',
\ '%a/tmptex.fls',
\ '%a/tmptex.latex',
\ '%a/tmptex.log',
\ '%a/tmptex.out',
\ ],
\}
vnoremap <silent><buffer> <F5> :QuickRun -mode v -type tmptex<CR>
" QuickRun and view compile result quickly (but don't preview pdf file)
nnoremap <silent><F5> :QuickRun<CR>
:QuickRun -args -pv
:QuickRun -args -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment