-
Notifications
You must be signed in to change notification settings - Fork 0
/
msctexen.sty
52 lines (50 loc) · 2.11 KB
/
msctexen.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
%!TEX encoding = UTF-8 Unicode
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
%
% Author: Andrzej Lichnerowicz (angelo@irc.pl)
% This code is based on http://www.imada.sdu.dk/~ehmsen/python.sty
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{msctexen}[2010/11/18 v0.1 Embed Mscgen in LaTeX]
\RequirePackage{keyval}
\RequirePackage{graphicx}
% Note: shell-escape needs to be activated for mscgen to work.
% (epstopdf still works, so you'll get missing input file error)
% This can either be done by passing -shell-escape as an option to
% latex, by adding/changing "shell_escape = t" in your texmf.cnf
% For details on Mscgen syntax see http://www.mcternan.me.uk/mscgen/
\newwrite\@out
\newcommand{\mscwidth}{\linewidth}
\begingroup \catcode `|=0 \catcode `[=1
\catcode`]=2 \catcode `\{=12 \catcode `\}=12
\catcode`\\=12 |gdef|@xmsc#1\end{msc}[|immediate|write|@out[#1]|end[msc]]
|endgroup
\define@key{msc}{width}{\def\msc@width{#1}}
\def\msc{\kernel@ifnextchar [{\@msc}{\@msc[]}}
\newcounter{msc@codenum}
\def\@msc[#1]{%
\let\msc@width=\mscwidth
\setkeys{msc}{#1}\stepcounter{msc@codenum}
\gdef\mscfname{msc/\jobname-\themsc@codenum}
\immediate\openout\@out=\mscfname.mscg
\newlinechar='15
\begingroup \catcode`\^^M=12 %
\let\do\@makeother\dospecials\obeyspaces%
\@xmsc}
\def\endmsc{%
\endgroup
\immediate\closeout\@out
\immediate\write18{mscgen -T eps -i \mscfname.mscg -o \mscfname.eps >\mscfname.out 2> \mscfname.err}
\immediate\write18{epstopdf \mscfname.eps }
{\includegraphics[width=\msc@width]{\mscfname}}}