Skip to content

Instantly share code, notes, and snippets.

@abcang
Last active August 29, 2015 14:03
Show Gist options
  • Save abcang/0ce3e8a8dfc64548620f to your computer and use it in GitHub Desktop.
Save abcang/0ce3e8a8dfc64548620f to your computer and use it in GitHub Desktop.
mdからpdfを作成するMakefile Markdownはreport.mdで、main.texから\inputで呼ぶ感じで
PANDOC = pandoc
PLATEX = pdfplatex
CONVERT = convert
OPTIONS = -N --no-highlight
TOFORMAT = -t latex
PDFNAME = report.pdf
TEXNAME = report.tex
SRCTEX = main.tex
SRCNAME = report.md
IMAGES = # 複数個指定可能.拡張子はepsで指定.
all: $(PDFNAME)
$(PDFNAME): $(TEXNAME)
$(PLATEX) $(SRCTEX) -o $(PDFNAME)
# 画像幅を10cmに
# 画像の位置をその場に固定
# longtableを通常のtableに変更
# 表のキャプションの位置を変更
$(TEXNAME): $(SRCNAME) $(IMAGES)
$(PANDOC) $(SRCNAME) $(OPTIONS) $(TOFORMAT) \
| sed 's/includegraphics/includegraphics[width=10cm]/g' \
| sed 's/{figure}\[htbp\]/{figure}\[H\]/g' \
| sed 's/\\addlinespace//g' \
| sed 's/\\midrule\\endhead/\\hline/g' \
| sed 's/\\toprule/\\hline/g' \
| sed 's/\\bottomrule/\\hline\\end{tabular}/g' \
| sed 's/{longtable}\[c\]/{table}[H]\\centering\\begin{tabular}/g' \
| sed 's/end{longtable}/end{table}/g' \
| php replace.php \
> $(TEXNAME)
.SUFFIXES: .eps .png
.png.eps:
$(CONVERT) $< $@
clean-without-pdf:; rm -f *.aux *.log *.dvi *.out *.eps
clean:; rm -f *.aux *.log *.dvi *.out *.eps $(PDFNAME)
# 参考
# http://qiita.com/mountcedar/items/e7603c2eb65661369c3b
# https://gist.github.com/syusui-s/190ad2a066d16f0b45bf
<?php
// 無理やり表のキャプションの位置を変更
echo preg_replace('/(.begin\{table\}\[H\])(.+?)(.caption.+?)(.end\{table\})/su', '$1$3$2$4', file_get_contents('php://stdin'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment