Skip to content

Instantly share code, notes, and snippets.

@kdmsnr
Last active September 3, 2021 05:25
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 kdmsnr/a726f63c752428692769c006c3059d6d to your computer and use it in GitHub Desktop.
Save kdmsnr/a726f63c752428692769c006c3059d6d to your computer and use it in GitHub Desktop.
  • pandocはtexファイルを作るまで使用するだけ
  • texファイルは自分でコンパイルする

1. Markdownに適当に書く

# タイトル

世紀の大発見でした[@book-first]

\appendix

# 参考文献

::: {#refs}
:::

※ ↑ の #refs は引用順で表示されるっぽい

2. cslとbibファイルを用意する

cslはsist02がよいらしい。 ref. https://zenn.dev/sky_y/articles/pandoc-advent-2020-bib2

.bibファイルは適当に。ここではrefs.bibとした。

3. markdown -> tex

pandoc input.md -f markdown-auto_identifiers -t latex --top-level-division=chapter --citeproc --bibliography=refs.bib --csl=sist02 -o latex/tmp.tex

4. tmp.tex から "\vadjust pre" を削除して body.tex に書き換える

スクリプトか何かで変換します。

ref. https://twitter.com/golden_lucky/status/1395655595844272131

5. main.tex を用意して以下を追加する

%% csl関連のあれこれ
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
 {% don't indent paragraphs
  \setlength{\parindent}{0pt}
  % turn on hanging indent if param 1 is 1
  \ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
  % set entry spacing
  \ifnum #2 > 0
  \setlength{\parskip}{#2\baselineskip}
  \fi
 }%
 {}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}

%% ...

%% さっきのファイルをインクルード
\include{body.tex}

6. latexをPDFにする

	platex    -kanji=utf8 main
	pbibtex   -kanji=utf8 main
	platex    -kanji=utf8 main
	platex    -kanji=utf8 main
	dvipdfmx  -p a4 main

Appendix. latexmkrcはこんなの用意した

$latex = 'uplatex';
$bibtex = 'upbibtex';
$dvipdf = 'dvipdfmx %O -o %D %S';
$makeindex = 'mendex -U %O -o %D %S';
$pdf_mode = 3; # dvipdfmxを使う
$ENV{TZ} = 'Asia/Tokyo';
$ENV{OPENTYPEFONTS} = '/usr/share/fonts//:';
$ENV{TTFONTS} = '/usr/share/fonts//:';
$aux_dir = 'build';
$out_dir = $aux_dir;
$pvc_view_file_via_temporary = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment