summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-11-01 22:56:55 +0000
committerKarl Berry <karl@freefriends.org>2010-11-01 22:56:55 +0000
commit7a633c81ad29409737208c24b0e92dd258862fcd (patch)
treeb977f4df249bab8d76ea1230a0c42727c0eb1b9a /Master
parent124ab1aa006529a0f1a3fa7c5fa7712e8eb558bf (diff)
context-filter (1nov10)
git-svn-id: svn://tug.org/texlive/trunk@20288 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/context/third/filter/filter.txt38
-rw-r--r--Master/texmf-dist/tex/context/third/filter/t-filter.tex73
2 files changed, 94 insertions, 17 deletions
diff --git a/Master/texmf-dist/doc/context/third/filter/filter.txt b/Master/texmf-dist/doc/context/third/filter/filter.txt
index 5cb0f7d5da7..6723e0d14e6 100644
--- a/Master/texmf-dist/doc/context/third/filter/filter.txt
+++ b/Master/texmf-dist/doc/context/third/filter/filter.txt
@@ -34,7 +34,7 @@ Installation
Writing installation instructions is always boring. If you are using ConTeXt
minimals, you can install the module using
- first-setup.sh --extras="t-filter"
+ first-setup.sh --extras="t-filter"
Depending on your TeX distribution, you may already have the module.
To verify, check if
@@ -187,7 +187,7 @@ By default, `\externalfilterinputfile` is set to `\jobname-<filter>.tmp`, where
is set, `\externalfilterinputfile` equals `\jobname-<filter>-<n>.tmp`, where
`<n>` is the number of filter environments that have appeared so far. In this
case, a `\jobname-<filter>-<n>.tmp.md5` file, which stores the `md5` sum of the
-input file` is also created.
+input file is also created.
A macro `\externalfilterbasefile` stores the name of the input file without the
extension. By default, the value of `\externalfilteroutputfile` is
@@ -221,6 +221,37 @@ where `\readPNGfile` is defined as
\def\readPNGfile#1{\externalfigure[#1]}
+Output Directory
+----------------
+
+This module creates a lot of temporary files that clutter the current directory.
+If you prefer the temporary files to be created in another directory, specify
+the `directory` option, e.g.,
+
+ \defineexternalfilter
+ [...]
+ [...
+ directory=output/,
+ ...]
+
+This will create all the temporary files in `output` directory. The name of the
+directory may be specified with or without a trailing slash. Thus,
+`directory=output` and `directory=output/` are both valid.
+
+The directory path **must be relative to the current directory**. Absolute paths
+do not work. If you try to use a absolute path like
+
+ \defineexternalfilter
+ [...]
+ [...
+ directory=/tmp/,
+ ...]
+
+you will get an error message
+
+ t-filter : Fatal Error: Cannot use absolute path /tmp/ as directory
+
+and compilation will stop.
Standard options
---------------
@@ -423,4 +454,7 @@ Version History
- Added `\traceexternalfilters` for tracing
- Added a message that shows filter command on console
- A message is shown on console when output file is not found.
+- **2010.10.30**:
+ - Added `directory=...` option to `\defineexternalfilter` and
+ `\setupexternalfilters`.
diff --git a/Master/texmf-dist/tex/context/third/filter/t-filter.tex b/Master/texmf-dist/tex/context/third/filter/t-filter.tex
index e2391a63619..5f7ba878e5c 100644
--- a/Master/texmf-dist/tex/context/third/filter/t-filter.tex
+++ b/Master/texmf-dist/tex/context/third/filter/t-filter.tex
@@ -1,6 +1,6 @@
%D \module
%D [ file=t-filter,
-%D version=2010.10.09
+%D version=2010.10.30
%D title=\CONTEXT\ User Module,
%D subtitle=Filter,
%D author=Aditya Mahajan,
@@ -36,9 +36,10 @@
%D \subsubject {Messages}
-\setinterfacemessage{externalfilter}{title} {\m!externalfilter}
-\setinterfacemessage{externalfilter}{notfound}{file -- cannot be found}
-\setinterfacemessage{externalfilter}{missing} {output file missing}
+\setinterfacemessage{externalfilter}{title} {\m!externalfilter}
+\setinterfacemessage{externalfilter}{notfound} {file -- cannot be found}
+\setinterfacemessage{externalfilter}{missing} {output file missing}
+\setinterfacemessage{externalfilter}{forbidden} {Fatal Error: Cannot use absolute path -- as directory}
%D \subsubject {Name space}
%D
@@ -88,6 +89,11 @@
\fi
\stoptexdefinition
+\def\doshowfilterstatus#1%
+ {\iftraceexternalfilters
+ \writestatus\m!externalfilter{#1}%
+ \fi}
+
\starttexdefinition doshowfiltercommand
\writestatus\m!externalfilter{command : \externalfilterparameter\c!filtercommand}
\stoptexdefinition
@@ -113,8 +119,9 @@
{\dodoubleargument\dodefineexternalfilter}
\def\dodefineexternalfilter[#1][#2]%
- {\edef\currentexternalfilter{#1}%
- \getparameters[\??externalfilter??#1][\s!parent=\??externalfilter??,#2]%
+ {\doshowfilterstatus{defining filter : #1}%
+ \edef\currentexternalfilter{#1}%
+ \getparameters[\??externalfilter??#1][\s!parent=\??externalfilter??,#2]%
\doif{\externalfilterparameter\c!continue}\v!yes
{\expandafter\newcounter\csname\externalfiltercountername\endcsname}%
\setvalue{\e!start#1}{\bgroup\obeylines\dodoubleargument\dostartexternalfilter[#1]}%
@@ -126,8 +133,8 @@
\def\dostartexternalfilter[#1][#2]% filter options
{% Initializations
\egroup %\bgroup in \start#1
- \begingroup % to keep assignments local
\edef\currentexternalfilter {#1}%
+ \begingroup % to keep assignments local
\getparameters[\??externalfilter??#1][\c!name=,#2]%
\setexternalfilterfilenames
% Capture the contents of the buffer
@@ -138,11 +145,14 @@
\edef\currentexternalfilter {#1}%
\getparameters[\??externalfilter??#1][\c!name=,#2]% TODO: Add continue=yes
% Currently filters with a pipe (|) fail with continue=yes
+ \setexternalfilterdirectory
\edef\externalfilterinputfile {#3}%
\splitfiletype {#3}%
%BEWARE. \edef doesn not work
\def\externalfilterbasefile {\splitoffname}%
- \def\externalfilteroutputfile{\externalfilterparameter\c!output}%
+ % The output is always in the directory specified by
+ % \c!directory; even if the input is from some other directory
+ \def\externalfilteroutputfile{\getexternalfilterdirectory\externalfilterparameter\c!output}%
\doshowfilterstate
\doexecuteexternalfilter
\doreadprocessedfile
@@ -192,14 +202,36 @@
%D \section {Helper Functions}
%D
+%D \subsubject {Set the name of output directory}
+
+\def\setexternalfilterdirectory
+ {\edef\getexternalfilterdirectory{\externalfilterparameter\c!directory}%
+ \doifsomething{\getexternalfilterdirectory}\dosetexternalfilterdirectory}
+
+\def\dosetexternalfilterdirectory
+ {\expandafter\docheckdirectorystart\getexternalfilterdirectory\@nil
+ \expandafter\docheckdirectorystop\getexternalfilterdirectory/\@nil}
+
+\def\docheckdirectorystart#1#2\@nil
+ {\doif{#1}{/}
+ {\writeline
+ \showmessage\??externalfilter??{forbidden}\getexternalfilterdirectory
+ \batchmode
+ \normalend}}
+
+\def\docheckdirectorystop#1#2/#3\@nil
+ {\edef\getexternalfilterdirectory{#1#2/}}
+
+
%D \subsubject {Set file names}
%D
%D \type{\externalfilterbasefile} is the name of the temporary file without
-%D extesion. Its actual value depends on the state of \type{continue} key as
+%D extension. Its actual value depends on the state of \type{continue} key as
%D well as the value of \type{name} key.
\def\setexternalfilterfilenames
- {% Set the name of temp file for os filter
+ {\setexternalfilterdirectory
+ % Set the name of temp file for the filter
\doifelse{\externalfilterparameter\c!continue}\v!yes
{\edef\externalfiltertmpfile{\??externalfilter??-\currentexternalfilter-\csname\externalfiltercountername\endcsname}}
{\edef\externalfiltertmpfile{\??externalfilter??-\currentexternalfilter}}
@@ -208,10 +240,20 @@
% The following macros are useful for filter= and filtercommand= options
% The basename of the external file
\edef\externalfilterbasefile {\jobname-\externalfiltertmpfile}%
- % The name of the buffer to which data is written
- \edef\externalfilterinputfile {\externalfilterbasefile.tmp}%
- % The name of the file to which the output is written
- \edef\externalfilteroutputfile{\externalfilterparameter\c!output}%
+ % In MkII, the buffer output is written to \TEXbufferfile{buffername} where
+ % the macro \TEXbufferfile is defined as
+ %
+ % \def\TEXbufferfile #1{\bufferprefix#1.\f!temporaryextension}
+ %
+ % We redefine bufferprefix to include the directory name.
+ \doifmode{\s!mkii}
+ {\edef\bufferprefix{\getexternalfilterdirectory\jobname-}}
+ % In MkIV, we do not need to do such jugglary, because we can specify the
+ % name of the file where the buffer has to be saved. This file is
+ % \externalfilterinputfile (because it is the input to the filter).
+ \edef\externalfilterinputfile {\getexternalfilterdirectory\externalfilterbasefile.\f!temporaryextension}%
+ % The name of the file to which the filter output is written
+ \edef\externalfilteroutputfile{\getexternalfilterdirectory\externalfilterparameter\c!output}%
\doshowfilterstate
}
@@ -222,7 +264,7 @@
\def\doprocessexternalfilter
{% By defualt, buffers are in memory in MkIV
- \doifmode\s!mkiv{\savebuffer[\externalfiltertmpfile]}%
+ \doifmode\s!mkiv{\savebuffer[\externalfiltertmpfile][\externalfilterinputfile]}%
% Run external command
\doexecuteexternalfilter
\doreadprocessedfile
@@ -274,6 +316,7 @@
\c!continue=\v!no,
\c!read=\v!yes,
\c!readcommand=\ReadFile,
+ \c!directory=,
\c!output=\externalfilterbasefile.tex,
\c!filter=,
\c!filtercommand={\externalfilterparameter\c!filter\space \externalfilterinputfile},