summaryrefslogtreecommitdiff
path: root/support/runtexshebang/README.md
blob: 7794c318e2e4772b84a1cfa1f3d90b44f51147c4 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# runtexshebang: Lua script running LaTeX document files with TeX-style shebang

Lua script running LaTeX document files with a TeX-style shebang (`%#!`)

## What is a TeX-style shebang (`%#!`)

In short, a TeX-style shebang (`%#!`) is a special kind of TeX comment 
that you include in your TeX/LaTeX document file to tell the operating system's 
shell how to run the file for the rest of the file: 

``` latex
%#!lualatex foo.tex
\documentclass{article}
\begin{document}
Hello, {\LaTeX} World!

Happy {\TeX}ing.
\end{document}
```

If you are using a TeX-style shebang, it must appear on the line that 
matched 20 lines or less in your LaTeX document, and it has to start with 
a TeX comment symbol (`%`) followed by a hash sign (`#`) and an exclamation mark (`!`), 
colloquially known as the bang, hence the name shebang for TeX/LaTeX. 


## Getting started

### 1. Install `runtexshebang.lua` in your TeX Live system.

``` shell
cp runtexshebang.lua /some/where/TEXMFDIST_or_TEXMFLOCAL/scripts/runtexshebang/runtexshebang.lua

cd TEXLIVE_BIN_DIRECTORY
ln -s ../../TEXMFDIST_or_TEXMFLOCAL/scripts/runtexshebang/runtexshebang.lua runtexshebang
```

### 2. Make a sample file with a TeX-style shebang.

Make the following LaTeX document. 

``` latex
%#!lualatex foo.tex
\documentclass{article}
\begin{document}
Hello, {\LaTeX} World!

Happy {\TeX}ing.
\end{document}
```

### 3. Run the sample file.

``` shell
runtexshebang foo.tex
```

Then, it will run `lualatex foo.tex`.


## Examples

### TeXworks

#### Settings

1. Open "Typesetting" tab in TeXworks Preferences.
2. Add the tool configuration "runtexshebang" in "Processing tools" as below.
        - Name: `runtexshebang`
        - Program: `runtexshebang`
        - Arguments: `$fullname`
        - ☑ View PDF after running (if necessary)

#### LaTeX document in the internal editor of TeXwork

`% !TEX program = ` is a magic comment of TeXworks.
You can set one processing tool as 
`% !TEX program = <your choice of tool configuration>`.

``` latex
% !TEX program = runtexshebang
%#! lualatex --synctex=1 foo
```


### LaTeX Workshop: Visual Studio Code

#### Settings

Nothing!

#### LaTeX document in Visual Studio Code

`% !TEX program = ` is a magic comment of LaTeX Workshop.
You need another magic comment to the target LaTeX document file as below. 

``` latex
% !TEX program = runtexshebang
% !TEX options = "%DOC%".tex
%#! lualatex --synctex=1 foo
```


### TeXShop

#### Settings

There the “Engine” settings for the command lines "TeX+dvipdfmx / TeX+dvips+distiller" as follows. 

* TeX: `runtexshebang`
* LaTeX: `runtexshebang`

#### LaTeX document in the internal editor of TeXShop

`% !TEX program = ` is a magic comment of TeXShop.

``` latex
% !TEX program = runtexshebang
%#! lualatex --synctex=1 foo
```


## Applications

### What does the PATH variable set in my editor?

``` latex
%#! echo $PATH
```

### How about general configuration information for the activated TeX Live version and its configuration in my editor?

``` latex
%#! tlmgr conf
```

### Otherwise

You can run any command line on your OSs.
For example, you can use any build tools as follows: 
`make`, `rake`, `llmk`, `latexmk`, and so on.

``` latex
%#! make foo.pdf

% #! rake foo.pdf
% #! llmk
% #! latexmk foo
%% and so on.
```

You can typeset a LaTeX document file in a Docker container as below. 

``` latex
%#! docker run -i --rm --workdir /data --mount type=bind,src=$(pwd)/,dst=/data/   bar/foo     lualatex foo
```


## References

### Commentary

* [TeXworks、TeXShop、VSCodeでTeX-style shebangしてみた - Qiita](https://qiita.com/munepi/items/a30c68133cfffbf4d189) (in Japanese)

### Tools supporting `%#!`

* [YaTeX](https://www.yatex.org/): Yet Another TeX mode for Emacs
* [llmk](https://github.com/wtsnjp/llmk): Light LaTeX Make



Enjoy Happy TeXing!


## License

This program is licensed under the terms of the MIT License.

--------------------

Munehiro Yamamoto
https://github.com/munepi