LoginSignup
12
7

More than 5 years have passed since last update.

IntelliJ IDEAでLaTeXを使う

Last updated at Posted at 2017-12-19

内容

本記事ではpLaTeX2e+pBibTeXを環境をIDEAで使用するための導入手順を述べる

利点

IntelliJ IDEAの優れた保管機能や見やすいUI、豊富な拡張機能を利用できる
また本導入によりbibとpdfの出力を1度に行えるようになる

前提・環境

OS:Windows10

Editor:IntelliJ IDEA (無料版有料版どちらでも動作)
公式サイト https://www.jetbrains.com/idea/

※学生の場合はUltimateEditonは無償
https://www.jetbrains.com/student/

コンパイラ、インタラプタ:
・pLaTeX2e (platex.exe)
・pBibTeX (pbibtex.exe)
・GhostScript
・dvipdfmx (dvipdfmx)

※これらを導入していない場合は、TeXインストーラ3を用いたインストールを薦める
http://www.math.sci.hokudai.ac.jp/~abenori/soft/abtexinst.html

※TeXWorksとdivoutのインストールは不要なので、ファイル取得後の画面でW32Texのファイル全てと、GhostScriptとGSViewの最新版のみにチェックを付けた状態でインストールすればよい

※他のコンパイラ(upLaTeX2eやupbibtexなど)を用いる場合でも、下記bat内でplatex → uplatexといったように適宜対応させる

手順

この手順の肝は、保管機能やファイル管理をTexiFyプラグインに任せ、コンパイル設定をbatで指定し、External toolsから呼び出すことにある

※TeXiFy-IDEAのgithubページ
https://github.com/Ruben-Sten/TeXiFy-IDEA

※このTeXiFyプラグインはpdfLaTeXおよびBibTeXをサポートしているが、日本語で論文書きたいならpLaTeX環境を推奨するため本導入が必要

1.TeXiFyプラグインをIDEAに導入

IDEAを起動し、
Settings → Plugins → Browse responsibilities → texify
で検索し、 TeXiFy を選択してインスコ
導入後IDEAを再起動

2.batファイルの作成

メモ帳を開き

output.bat
@echo off
set resPath=%~f1%\src
set mainResPath=%resPath%\main
set outputPath=%~f1%\out
set mainOutPath=%outputPath%\main

rem bibを出力用のパスにコピー, auxが参照できるようにする
call copy %mainResPath%.bib %mainOutPath%.bib 
rem aux作成
call platex -output-directory=%outputPath% -synctex=1 -jobname=main -kanji=utf8 -guess-input-enc %mainResPath%
rem auxを参照してpbibtexがbbl(blg)を作成
call pbibtex main -kanji=utf8
rem auxとbblを紐付け
call platex -output-directory=%outputPath% -synctex=1 -jobname=main -kanji=utf8 -guess-input-enc %mainResPath%
rem 上記の紐付けを参照にしてpdf作成
call platex -output-directory=%outputPath% -synctex=1 -jobname=main -kanji=utf8 -guess-input-enc %mainResPath% && dvipdfmx %mainOutPath%
rem コピーしたbibは邪魔なので消す
call del main.bib
rem pdfを開く
start %mainOutPath%.pdf
exit 0

上記のようなbatファイルを作成する
ほぼコピペでいいはずだが、必要に応じてパスを変更する

※リソースパス・出力パスの指定は、TeXiFyプラグインのLaTeXプロジェクトの新規作成で自動生成されるディレクトリに従う

※前述した通りupLatexを使いたい場合は、上記コード上のplatexをuplatexに変更し、

main.tex
\documentclass[uplatex]{jsarticle}

とドキュメントクラスに追記する必要がある.

3.IDEAに上記batファイルを適用する

Settings → External tools → add
を選択し、以下のようにディレクトリを指定する

Name:pLaTeX2e+pBibTeX
Program:output.bat (手順2で作成したbatファイルを選択)
Arguments:\$FileParentDir\$
Working directory:\$FileParentDir\$\out

4.出力

編集中のファイルから
Tools → External tools → pLaTeX2e+pBibTeX
を選択するとpdfが表示される

※ショートカットキーに指定すると良い

5.インスペクションの無効

日本語入力すると

"Non-ASCII characters are not supported by LaTeX out-of-the-box."

という理由でインスペクションが現れてしまうが、上記設定でUTF-8などに対応するようになるため、上記の警告を無効にする必要がある

Settings → Editor → Inspections
より
"Unsupported Unicode character"
のチェックを外す
Copy to IDEすれば他のプロジェクトにも反映されて便利

※Alt+Enterからも設定できる

6.画像のディレクトリ

上記設定だと画像をoutフォルダに入れなければならないが

main.tex
%dvipdfmxを使うように指定
\usepackage[dvipdfmx]{graphicx}
%画像フォルダの指定
\graphicspath{{../src/}}

と記述すればsrcフォルダ内に画像を保存できる

※テンプレートファイル作ると楽
Settings → File and Code Templates → Files → +
より追加できる
.texファイルの例
https://pastebin.com/8ChThfRh
.bibファイルの例
https://pastebin.com/smeJky44

12
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
7