summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/support/texosquery/README.md
blob: bad3733503ae83ad22d9274ac6120ea799d112cd (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# texosquery
Cross-platform Java application to query OS information designed for use in 
TeX's shell escape mechanism.

The application can query the following:

 - locale information
 - default file encoding
 - current working directory
 - user home directory
 - temporary directory
 - OS name, arch and version
 - Current date and time in PDF format
   (for TeX formats that don't provide `\pdfcreationdate`)
 - Date-time stamp of a file in PDF format
   (for TeX formats that don't provide `\pdffilemoddate`)
 - Size of a file in bytes
   (for TeX formats that don't provide `\pdffilesize`)
 - Contents of a directory (captured as a list)
 - Directory contents filtered by regular expression
   (captured as a list)
 - URI of a file
 - Canonical path of a file

All paths use a forward slash as directory divider so results
can be used, for example, in commands like `\includegraphics`.

There are files provided for easy access in (La)TeX documents:

 - `texosquery.tex` : generic TeX code
 - `texosquery.sty` : LaTeX package

This provides the command `\TeXOSQuery` to run `texosquery` using
TeX's shell escape mechanism and capture the result in a control
sequence.  The category code of most of TeX's default special
characters (and some other potentially problematic characters) is
temporarily changed to 12 while reading the result. Some of the
`texosquery` output contains short markup commands (such as `\wrp`)
which are internally converted within `\TeXOSQuery`.

## Installation

Installation is best done using your TeX package manager.
Manual installation instructions are described below.
For more detail, see the documentation.

### Compiling the Documentation

To compile the documentation:
```bash
pdflatex texosquery.dtx
makeglossaries texosquery
makeindex -s gglo.ist -t texosquery.glg -o texosquery.gls texosquery.glo
pdflatex texosquery.dtx
makeindex -s gind.ist texosquery.idx
pdflatex texosquery.dtx
pdflatex texosquery.dtx
```

### Extracting the Files

Except for the `.jar` files, the `texosquery` files are all
bundled inside `texosquery.dtx` with the extraction commands
provided in `texosquery.ins`. To extract all the files do:
```bash
tex texosquery.ins
```

The `.sh` files are bash scripts for Unix-like users. These will
need to be set to executable using `chmod`. I recommend
that you also remove the `.sh` extension. Windows users can
deleted these files.

The `.batch` files are batch scripts for Windows users. Unix-like
users can delete these files. These files are given the extension
`.batch` as TeX on Windows doesn't allow the creation of `.bat`
files. The extension will need to be changed to `.bat` after the
files have been extracted.

### Installing the Application

In the following, replace _TEXMF_ with the path to your TEXMF directory.
You can find your home TEXMF directory using
```bash
kpsewhich -var-value=TEXMFHOME
```

There are now three Java applications provided by this package:

 - `texosquery.jar` (requires at least Java 7)
 - `texosquery-jre8.jar` (requires at least Java 8)
 - `texosquery-jre5.jar` (requires at least Java 5)

There are corresponding bash scripts for Unix-like users (the `.sh`
extension added by `texosquery.ins` should be removed and the files
made executable):

 - `texosquery`
 - `texosquery-jre8`
 - `texosquery-jre5`

There are also corresponding batch scripts for Windows users (the `.batch`
extension created by the `.ins` file should be changed to `.bat`):

 - `texosquery.bat`
 - `texosquery-jre8.bat`
 - `texosquery-jre5.bat`

Each script uses `kpsewhich` to find the corresponding `.jar` file
and runs it.

Put the `.jar` files in _TEXMF_`/scripts/texosquery/` and the
bash or `.bat` files somewhere on your path. You may or may not need
to refresh the TeX database.

To test the installation, run
```bash
texosquery -v
```
in the command prompt or terminal. (Also try with `texosquery-jre8`
and `texosquery-jre5`.)

If successful, it should show the version number.

### Installing the TeX Code

The `.tex`, `.cfg` and `.sty` files should all be extracted from `texosquery.dtx`
with `tex texosquery.ins` as described above.

 - Move `texosquery.tex` to _TEXMF_`/tex/generic/texosquery/`
 - Move `texosquery.cfg` to _TEXMF_`/tex/generic/texosquery/`
 - Move `texosquery.sty` to _TEXMF_`/tex/latex/texosquery/`
 - Move `texosquery.pdf` to _TEXMF_`/doc/generic/texosquery/`

The `texosquery.cfg` file allows you to specify which application you
want to use. First check which version of the Java Runtime
Environment (JRE) you have installed:
```bash
java -version
```
This should display the version information. (For example, `"1.8.0_92"`)

If the version number starts with `1.8` (“Java 8”), then you can use `texosquery-jre8.jar`.
This is the full application. You can use `texosquery` or 
`texosquery-jre5` as well, but there's less locale support with them. 
The `texosquery-jre8` bash script and `texosquery-jre8.bat` batch script invokes Java with 
`-Djava.locale.providers=CLDR,JRE`.

If Windows users have simply been supplied with an executable versions
of the `texosquery-jre8.jar` file (`texosquery-jre8.exe`) then you'll have to set the
`JAVA_TOOL_OPTIONS` environment variable instead.
 
This `java.locale.providers` setting allows Java to access locale
information from the [Unicode Common Locale Data Repository
(CLDR)](http://cldr.unicode.org/) installed on their system. The
pending Java 9 should include this by default, so this will only be
relevant to Java 8. Earlier versions of Java (7 or below) don't have
this option, which limits the locale support to that which is
natively provided by the JRE.

If the version information starts with `1.7` (“Java 7”), then you can use 
`texosquery.jar`. This is the default application and provides most
of the functions of the full application, but there's less locale support.
You can also use the even more limited `texosquery-jre5`, but you can't use
`texosquery-jre8`, so you can't take advantage of the CLDR.

If the version information starts with `1.5` (“Java 5”) or `1.6`
(“Java 6”), then you can _only_ use `texosquery-jre5`.  The locale
support is significantly reduced in this case and there's no support
for language scripts. Note that these versions of Java are
deprecated.

Once you have determined which application you want to use, edit the
`texosquery.cfg` so that `\TeXOSInvokerName` is defined to the appropriate invocation. For example, with Java 8:
```tex
\def\TeXOSInvokerName{texosquery-jre8}
```
or with Java 5 or 6:
```tex
\def\TeXOSInvokerName{texosquery-jre5}
```
(bash users will have to add the `.sh` extension if it hasn't
been removed, as per the above instructions.)

## Examples:

Plain TeX:

```tex
% arara: pdftex: {shell: on}
\input texosquery

\TeXOSQuery{\result}{-b}
IEFT BCP 47 language tag: \result.

\TeXOSQueryLocale{\result}
POSIX locale: \result.

\TeXOSQueryCwd{\result}
cwd: {\tt \result}.

\TeXOSQueryNow{\result}
now: \result.

\TeXOSQueryFileDate{\result}{\jobname.tex}
file date: \result.

\TeXOSQueryFileSize{\result}{\jobname.tex}
file size: \result bytes.

\bye
```

LaTeX:

```latex
% arara: pdflatex: {shell: on}
\documentclass{article}

\usepackage{texosquery}
\usepackage{etoolbox}

\begin{document}

\TeXOSQuery{\result}{-b}
IEFT BCP 47 language tag: \result.

\TeXOSQueryLocale{\result}
POSIX locale: \result.

\TeXOSQueryCwd{\result}
cwd: \texttt{\result}.

\TeXOSQueryNow{\result}
now: \result.

\TeXOSQueryFileDate{\result}{\jobname.tex}
file date: \result.

\TeXOSQueryFileSize{\result}{\jobname.tex}
file size: \result bytes.

\TeXOSQueryFilterFileList{\result}{,}{.+\string\.(png|jpg)}{.}
All jpg and png files in current directory:

\renewcommand{\do}[1]{\texttt{#1}.\par}
\expandafter\docsvlist\expandafter{\result}

\end{document}
```

For a full list of available commands, see the documentation
(`texosquery.pdf`).

## Source code

The Java source is in the `.java` files and the manifest for each 
`.jar` file is `Manifest*.txt` (`Manifest-jre8.txt` for `texosquery-jre8` etc). 
Assuming the following directory structure:
```
java/TeXOSQuery.java
java/TeXOSQueryJRE5.java
java/TeXOSQueryJRE7.java
java/TeXOSQueryJRE8.java
java/QueryAction.java
java/QueryActionType.java
java/FileSortType.java
java/FileSortComparator.java
java/FileListType.java
java/FileWalkVisitor.java
java/Manifest-jre5.txt
java/Manifest-jre7.txt
java/Manifest-jre8.txt
classes/com/dickimawbooks/texosquery/
```
Then to create `texosquery-jre8.jar`, do (for JDK version 1.8):
```bash
cd java 
javac -d ../classes TeXOSQuery.java QueryAction.java QueryActionType.java TeXOSQueryJRE8.java FileSortType.java FileSortComparator.java FileListType.java FileWalkVisitor.java
cd ../classes
jar cmf ../java/Manifest-jre8.txt ../texosquery-jre8.jar com/dickimawbooks/texosquery/*.class
```

Similarly for the other `.jar` files, replacing `8` with `7` or `5`.
(The Java 7 version should really be `texosquery-jre7.jar`, but is
simply named `texosquery.jar` in the distribution for backward compatibility reasons. If you compile the code, the `.jar` name is your choice.)

---

Source on GitHub: https://github.com/nlct/texosquery

Author Home Page: http://www.dickimaw-books.com/

License: LPPL 1.3+