ラベル TeX の投稿を表示しています。 すべての投稿を表示
ラベル TeX の投稿を表示しています。 すべての投稿を表示

2016年6月19日日曜日

TeXのパッケージのインストール

前回は、最低限TeXが動くようにするところまでは行ったので、パッケージをインストールする方法について書きます。

とりあえず、bm.styを使えるようにすることを目標にします。

CTANからダウンロード

まずはCTANというTeXのパッケージなどをまとめているサイトへ行き、必要なファイルをインストールします。
検索Boxのところにキーワードを打ち込んで欲しいパッケージをまずは見つけます。今回は「bm」と打ちました。

検索をすると、このような画面になります。

「Package bm」のリンクをクリックします。


TDS archiveの行にある.zipファイルをクリックすればダウンロードされます。
それを解凍します。
今回の場合、解凍されてできるのは、latex-tools.tdsです。

styファイルの生成

styleファイル(拡張子が.styのファイル)は.insのファイルと.dtxのファイルから生成します。
今回の場合はbm.insとbm.dtxのファイルです。まずはこの二つのある場所を探します。
探してみると、latex-tools.tds→source→latex→toolsの中にあることがわかります。

カレントディレクトリをtoolsに移動します。(絶対パスで移動するなり、相対パスで地道に移動するなりして)

そこで、
hiroshi-no-MacBook-Air:tools hiroshi$ sudo latex bm.ins

とコマンドを打ちます。例によってパスワードを求められるので自分のPCのパスワードを入力します。
そうすると、以下のような処理が始まり、bm.styが生成されます。あとbm.logもできます。
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(./bm.ins
LaTeX2e <2015>
Babel <3 .9l=""> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/docstrip.tex
Utility: `docstrip' 2.5e <2014>
English documentation    <2014>

**********************************************************
* This program converts documented macro-files into fast *
* loadable files by stripping off (nearly) all comments! *
**********************************************************

********************************************************
* No Configuration file found, using default settings. *
********************************************************

)

Generating file(s) ./bm.sty 

Processing file bm.dtx (package) -> bm.sty
Lines  processed: 1679
Comments removed: 1262
Comments  passed: 5
Codelines passed: 403

 )
No pages of output.
Transcript written on bm.log.



もし、
sudo: latex: command not found

とかいうエラーがでたらそれはPATHが通っていません。

hiroshi-no-MacBook-Air:tools hiroshi$ PATH=/Library/TeX/texbin:$PATH

として「Library/Tex/texbin」にPATHを通してから再度実行しましょう。

生成したファイル類をまとめる。

生成に要した.insと.dtxと、生成された.styと.logを別フォルダにまとめます。

「/usr/local/texlive/texmf-local/tex/latex/local」の中に、新しいフォルダを作成します。
今回は「bm」という名前のフォルダにしておきます。
その中に、上記4つのファイルを移動させれば完了です。

これでbmというパッケージが使用できるようになります。
参考にしたページや文献・書籍
パッケージについて
CTAN

El'CapitanにMacTeXのインストール

最近、TeXで資料を作らなければならない状況があったため、TeX環境を入れました。

まあ過去にwindowsとかに入れたこともあったりするのですが、Macに入れる手順も自分の忘備録として残しておきたいと思います。

前提としている環境は以下の状況です。

Homebrew Caskのインストール

まずHomebrewの拡張であるHomebrewcaskをインストールします。
ターミナルを開き以下のようにコマンドを実行します。
hiroshi-no-MacBook-Air:~ hiroshi$ sudo brew tap caskroom/cask

sudoで実行しているので、パスワードを求められます。自分のパソコンにログインするときのパスワードを入力すると、以下のように処理が始まります。
==> Tapping caskroom/cask
Cloning into '/usr/local/Library/Taps/caskroom/homebrew-cask'...
remote: Counting objects: 3710, done.
remote: Compressing objects: 100% (3655/3655), done.
remote: Total 3710 (delta 63), reused 865 (delta 34), pack-reused 0
Receiving objects: 100% (3710/3710), 6.48 MiB | 880.00 KiB/s, done.
Resolving deltas: 100% (63/63), done.
Checking connectivity... done.
Tapped 1 formula (3,675 files, 15.2M)
hiroshi-no-MacBook-Air:~ hiroshi$

処理はすぐ終わるので、終わったらさらに次のようにコマンドを打ちます。

hiroshi-no-MacBook-Air:~ hiroshi$ sudo brew install caskroom/cask/brew-cask

そうすうと以下のようになります。

==> Installing brew-cask from caskroom/cask
==> Cloning https://github.com/caskroom/homebrew-cask.git
Cloning into '/Library/Caches/Homebrew/brew-cask--git'...
remote: Counting objects: 3408, done.
remote: Compressing objects: 100% (3369/3369), done.
remote: Total 3408 (delta 56), reused 528 (delta 18), pack-reused 0
Receiving objects: 100% (3408/3408), 5.88 MiB | 4.06 MiB/s, done.
Resolving deltas: 100% (56/56), done.
Checking connectivity... done.
Note: checking out 'b4c92f3658d47712aa6114fb29be50a763cf78ee'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b 

==> Checking out tag v0.60.1
==> Caveats
You must uninstall this formula. It is no longer needed to stay up to date,
as Homebrew now takes care of that automatically.
==> Summary
🍺  /usr/local/Cellar/brew-cask/0.60.1: 4 files, 7.6K, built in 11 seconds
hiroshi-no-MacBook-Air:~ hiroshi$

MacTeXのインストール

いまインストールしたHomebrewCaskを使ってMacTeXをインストールします。
同様にターミナルで次のように打ちます。
hiroshi-no-MacBook-Air:~ hiroshi$ sudo brew cask install mactex

つぎのような処理が始まります。

==> We need to make Caskroom for the first time at /opt/homebrew-cask/Caskroom
==> We'll set permissions properly so we won't need sudo in the future
==> Downloading http://tug.org/cgi-bin/mactex-download/MacTeX.pkg
######################################################################## 100.0%
==> Verifying checksum for Cask mactex
==> Running installer for mactex; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
==> installer: Package name is MacTeX-2015
==> installer: Installing at base path /
==> installer: The install was successful.
🍺  mactex staged at '/opt/homebrew-cask/Caskroom/mactex/20150613' (2.5G)
hiroshi-no-MacBook-Air:~ hiroshi$

特に問題なく完了すれば、Finderのアプリケーションディレクトリの中にTeXのフォルダができています。


で、そのTeXフォルダの中にはこんなものが入ってます。


TeXShopがいわゆる統合開発環境です。

PATHを通す

しかし、このままではまだTeXは動きません。

試しにTeXshopを起動し、こんな感じで打ってみます。

これで左上に表示されている「タイプセット」のボタンを押せばpdfファイルが出力されるはずなのですが、こんなエラーが表示されてしまいます。




どうやらいろいろ調べてみると、El'CapitanからPATHを通す場所が違うようです。

画面左上から「TeXShop→環境設定→内部設定」と進み、パス設定の中の「(pdf)TeX」を編集します。

デフォルトは、「/usr/texbin」になっているようですが、これを消して、「/Library/TeX/texbin」と入力します。

それで「OK」を押します。

それでもう一度「タイプセット」を押すと、無事pdfファイルが出力されます。されるはずです。されなかったらごめんなさい。

ちなみに、ターミナルのほうで直接PATHは通す必要はないようです。
シェルのコマンドでPATHからTeXに関するコマンドを削除しても、少なくとも上記環境設定でPATHが通っていれば大丈夫なようです。


最低限の記述はこれでできるようになりましたが、パッケージなどはまだ使えません。

パッケージのインストール方法は、これはこれでまた若干手順があるので、またの機会にします。