summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/context/third/filter/filter.txt45
-rw-r--r--Master/texmf-dist/tex/context/third/filter/t-filter.mkii132
-rw-r--r--Master/texmf-dist/tex/context/third/filter/t-filter.mkiv61
3 files changed, 155 insertions, 83 deletions
diff --git a/Master/texmf-dist/doc/context/third/filter/filter.txt b/Master/texmf-dist/doc/context/third/filter/filter.txt
index 93d8df6e12b..b98325b2fec 100644
--- a/Master/texmf-dist/doc/context/third/filter/filter.txt
+++ b/Master/texmf-dist/doc/context/third/filter/filter.txt
@@ -141,6 +141,37 @@ The above `\defineexternalfilter` macro defines:
The [wiki](https://github.com/adityam/filter/wiki) page on Github gives the
setup for common usecases (pandoc, R, etc.)
+Inheriting setup from other commands
+-------------------------------------
+
+It is also possible to inherit the settings from another filter. For example,
+
+ \defineexternalfilter
+ [filterstyle]
+ [color=red,
+ style=bold]
+
+ \defineexternalfilter
+ [markdown]
+ [filterstyle]
+ [filter={pandoc -w context -o \externalfilteroutputfile },
+ style=italic]
+
+Notice the three arguments to `\defineexternalfilter`. The first argument
+(`markdown`) is the name of the new filter; the second argument (`filterstyle`)
+is the name of the filter whose settings we want to inherit, and the third
+argument (`filter=...`) are the new settings for `markdown` filter. The above
+definition is same as:
+
+ \defineexternalfilter
+ [filter={pandoc -w context -o \externalfilteroutputfile },
+ style=italic,
+ color=red]
+
+Note that if a setting (like `style` above) is defined both in the new filter
+and the parent filter, then the value of the new filter (`style=italic` above)
+is used.
+
Dealing with slow filters
-------------------------
@@ -493,10 +524,15 @@ file. To use such markdown files in ConTeXt, I can just use
\processmarkdownfile{filename.md}
+By default, the file is searched the current directory and in the directories
+specified by `\usepath`. In addition, in MkIV, the parent and grand-parent
+directories are also searched. If the file is not in one of these locations,
+specify a full or a relative path to the file.
+
The general macro is `\process<filter>file{...}`, which takes the name of a file
-**or a url** as an argument and uses that file as the input file for the filter. The rest of
-the processing is the same as with `\start<filter>` ... `\stop<filter>`
-environment.
+**or a url (MkIV only)** as an argument and uses that file as the input file for
+the filter. The rest of the processing is the same as with `\start<filter>` ...
+`\stop<filter>` environment.
The `\process<filter>file` macro also takes an optional argument for setup
options:
@@ -539,7 +575,6 @@ or use
to compile the file.
-
Processing existing buffers
---------------------------
@@ -851,3 +886,5 @@ Version History
- Added `location`, `spacebefore` and `spaceafter` keys.
- **2012.05.01**
- Added `align` key.
+- **2012.06.20**
+ - Support for `\usepath`
diff --git a/Master/texmf-dist/tex/context/third/filter/t-filter.mkii b/Master/texmf-dist/tex/context/third/filter/t-filter.mkii
index 3bcb6c3095c..560f9003ffd 100644
--- a/Master/texmf-dist/tex/context/third/filter/t-filter.mkii
+++ b/Master/texmf-dist/tex/context/third/filter/t-filter.mkii
@@ -1,6 +1,6 @@
%D \module
%D [ file=t-filter,
-%D version=2012.05.16,
+%D version=2012.06.20,
%D title=\CONTEXT\ User Module,
%D subtitle=Filter,
%D author=Aditya Mahajan,
@@ -9,7 +9,7 @@
%D email=adityam <at> ieee <dot> org,
%D license=Simplified BSD License]
-\writestatus{loading}{Filter (ver: 2012.05.16)}
+\writestatus{loading}{Filter (ver: 2012.06.20)}
\ifx\undefined\normalexpanded \let\normalexpanded\expanded \fi
@@ -53,15 +53,33 @@
%D We use logical names to easily catch typos.
\def\externalfilter@id {externalfilter}
-\def\externalfilter@namespace {@@@@\externalfilter@id}
-\def\externalfilter@name {}
+\def\????externalfilter {@@@@\externalfilter@id}
\def\externalfilter@temp_prefix {temp}
-\def\externalfilter@count {\externalfilter@namespace-\externalfilter@name-counter}
+\def\externalfilter@count {\????externalfilter-\currentexternalfilter-counter}
+
+\installparameterhandler \????externalfilter \externalfilter@id
+\installparameterhashhandler \????externalfilter \externalfilter@id
+\installsetuphandler \????externalfilter \externalfilter@id
+\installdefinehandler \????externalfilter \externalfilter@id \????externalfilter
+
+\ifx\undefined\setuvalue
+ \def\setuvalue #1{\normalprotected\expandafter \def\csname#1\endcsname}
+ \def\setuevalue #1{\normalprotected\expandafter\edef\csname#1\endcsname}
+\fi
+
+\appendtoks
+ \externalfilter@show_status{defining filter : \currentexternalfilter}%
+ \doifinset{\externalfilterparameter\c!cache}{\v!yes,\v!force}
+ {\ifcsname\externalfilter@count\endcsname \else
+ \expandafter\newcounter\csname\externalfilter@count\endcsname\fi}%
+ \setuevalue{\e!start\currentexternalfilter}{\externalfilter@start[\currentexternalfilter]}%
+ \setuvalue {\e!stop\currentexternalfilter}{\externalfilter@process_filter}%
+ \setuevalue{process\currentexternalfilter file}{\externalfilter@process_file[\currentexternalfilter]}%
+ \setuevalue{process\currentexternalfilter buffer}{\externalfilter@process_buffer[\currentexternalfilter]}%
+ \setuevalue{inline\currentexternalfilter}{\externalfilter@inline[\currentexternalfilter]}%
+\to \everydefineexternalfilter
-\installparameterhandler \externalfilter@namespace \externalfilter@id
-\installparameterhashhandler \externalfilter@namespace \externalfilter@id
-\installsetuphandler \externalfilter@namespace \externalfilter@id
% For backward compatibility
\let\setupexternalfilters \setupexternalfilter
@@ -83,11 +101,11 @@
\newif\iftraceexternalfilters
-\def\traceexternalfilters
+\unexpanded\def\traceexternalfilters
{\traceexternalfilterstrue}
\starttexdefinition externalfilter@show_filenames
- \writestatus\m!externalfilter{current filter : \externalfilter@name}
+ \writestatus\m!externalfilter{current filter : \currentexternalfilter}
\writestatus\m!externalfilter{base file : \externalfilter@base_file}
\writestatus\m!externalfilter{input file : \externalfilter@input_file}
\writestatus\m!externalfilter{output file : \externalfilter@output_file}
@@ -106,36 +124,16 @@
%D \section {The main user macros}
-%D \subsubject {Define a new filter}
-
-\def\defineexternalfilter
- {\dodoubleargument\externalfilter@define}
-
-\starttexdefinition externalfilter@define [#1][#2]
- \externalfilter@show_status{defining filter : #1}
-
- \setupexternalfilter[#1][\s!parent=\externalfilter@namespace,#2]
- \edef\externalfilter@name{#1}
-
- \doifinset{\externalfilterparameter\c!cache}{\v!yes,\v!force}
- {\expandafter\newcounter\csname\externalfilter@count\endcsname}
-
- \setvalue{\e!start#1}{\bgroup\obeylines\dodoubleargument\externalfilter@start[#1]}
- \setvalue {\e!stop#1}{\externalfilter@process_filter}
-
- \setvalue{process#1file}{\dodoubleargument\externalfilter@process_file[#1]}
- \setvalue{process#1buffer}{\dotripleargument\externalfilter@process_buffer[#1]}
- \setvalue{inline#1}{\dodoubleargument\externalfilter@inline[#1]}
+\unexpanded\def\externalfilter@start
+ {\bgroup\obeylines\dodoubleargument\externalfilter@start_indeed}
-\stoptexdefinition
-
-\starttexdefinition externalfilter@start [#1][#2]
+\starttexdefinition externalfilter@start_indeed [#1][#2]
% #1 = filter
% #2 = options
- \egroup %\bgroup in \start#1
+ \egroup %\bgroup in \externalfilter@start
\begingroup % to keep assignments local
- \edef\externalfilter@name{#1}
+ \edef\currentexternalfilter{#1}
\setupexternalfilter[#1][\c!name=,#2]
@@ -145,18 +143,27 @@
\dostartbuffer[\externalfilter@buffer_name][\e!start#1][\e!stop#1]
\stoptexdefinition
-\starttexdefinition externalfilter@process_file [#1][#2]#3
+\unexpanded\def\externalfilter@process_file
+ {\dodoubleargument\externalfilter@process_file_indeed}
+
+\starttexdefinition externalfilter@process_file_indeed [#1][#2]#3
% #1 = filter
% #2 = options
% #3 = filename
\begingroup
- \edef\externalfilter@name{#1}
+ \edef\currentexternalfilter{#1}
\setupexternalfilter[#1][\c!name=,#2]
\externalfilter@set_directory
- \edef\externalfilter@input_file{#3}
+ \locatefilepath{#3}
+ \ifx\locatedfilepath\empty
+ % FIXME: Should we declare an error?
+ \edef\externalfilter@input_file{#3}
+ \else
+ \edef\externalfilter@input_file{\pathplusfile\locatedfilepath{#3}}
+ \fi
\splitfilename{#3}
%NOTE: \edef doesn not work because \splitoffname is not expandable
\def\externalfilter@base_file {\splitoffname}
@@ -172,13 +179,16 @@
\endgroup
\stoptexdefinition
-\starttexdefinition externalfilter@process_buffer [#1][#2][#3]
+\unexpanded\def\externalfilter@process_buffer
+ {\dotripleargument\externalfilter@process_buffer_indeed}
+
+\starttexdefinition externalfilter@process_buffer_indeed [#1][#2][#3]
% #1 = filter
% #2 = options
% #3 = buffer
\begingroup
- \edef\externalfilter@name{#1}
+ \edef\currentexternalfilter{#1}
\ifthirdargument
\setupexternalfilter[#1][\c!name=,#2]
\fi
@@ -192,9 +202,6 @@
\fi
\externalfilter@set_filenames_extras
- % In MkII, the above function sets the wrong value of
- % \type{\externalfilter@input_file}. So, we reset that name here.
- \edef\externalfilter@input_file {\externalfilter@base_file.\f!temporaryextension}
\iftraceexternalfilters \externalfilter@show_filenames \fi
@@ -202,16 +209,19 @@
\stoptexdefinition
-\starttexdefinition externalfilter@inline [#1][#2]
+\unexpanded\def\externalfilter@inline
+ {\dodoubleargument\externalfilter@inline_indeed}
+
+\starttexdefinition externalfilter@inline_indeed [#1][#2]
\begingroup % to keep assignments local
- \edef\externalfilter@name{#1}
+ \edef\currentexternalfilter{#1}
\setupexternalfilter[#1][\c!numbering=,\c!name=,\c!location=\v!text,#2]
\externalfilter@set_filenames
\pushcatcodetable
- \futurelet\next\externalfilter@inline_indeed
+ \futurelet\next\externalfilter@inline_grabcontent
\stoptexdefinition
%D \subsubject {Write argument to file verbatim}
@@ -219,7 +229,7 @@
%D Surprisingly, there is nothing in the core to define a function that write its
%D argument to a file verbatim. I basically copied the \type{\type} macro.
-\starttexdefinition externalfilter@inline_indeed
+\starttexdefinition externalfilter@inline_grabcontent
\ifx\next\bgroup
\expandafter\externalfilter@inline_group
\else
@@ -254,7 +264,7 @@
% Finalization
\doifinset{\externalfilterparameter\c!cache}{\v!yes,\v!force}
- {\doglobal\expandafter\increment\csname\externalfilter@count\endcsname}
+ {\doglobal\incrementvalue\externalfilter@count}
\endgroup
\stoptexdefinition
@@ -304,7 +314,7 @@
\normalend}
\doifnot{\externalfilter@get_last_character\externalfilter@get_directory}{/}
- {\showmessage\m!externalfilter{slash}\externalfilter@get_directory
+ {\iftraceexternalfilters \showmessage\m!externalfilter{slash}\externalfilter@get_directory \fi
\edef\externalfilter@get_directory{\externalfilter@get_directory/}}
\stoptexdefinition
@@ -321,11 +331,10 @@
% Set the name of temp file for the filter
\doifinsetelse{\externalfilterparameter\c!cache}{\v!yes,\v!force}
- {\edef\externalfilter@buffer_name{\externalfilter@temp_prefix-\externalfilter@name-\csname\externalfilter@count\endcsname}}
- {\edef\externalfilter@buffer_name{\externalfilter@temp_prefix-\externalfilter@name}}
+ {\edef\externalfilter@buffer_name{\externalfilter@temp_prefix-\currentexternalfilter-\csname\externalfilter@count\endcsname}}
+ {\edef\externalfilter@buffer_name{\externalfilter@temp_prefix-\currentexternalfilter}}
\doifsomething{\externalfilterparameter\c!name}
- {\edef\externalfilter@buffer_name{\externalfilter@temp_prefix-\externalfilter@name-\externalfilterparameter\c!name}}
-
+ {\edef\externalfilter@buffer_name{\externalfilter@temp_prefix-\currentexternalfilter-\externalfilterparameter\c!name}}
\externalfilter@set_filenames_extras
@@ -359,21 +368,22 @@
\starttexdefinition externalfilter@process_filter
\externalfilter@execute_filter
\externalfilter@read_processed_file
- \endgroup
% Finalization
\doifinset{\externalfilterparameter\c!cache}{\v!yes,\v!force}
- {\doglobal\expandafter\increment\csname\externalfilter@count\endcsname}
+ {\doglobal\incrementvalue\externalfilter@count}
- \expanded{\checknextindentation[\externalfilterparameter\c!indentnext]}
- \dorechecknextindentation
+ \doif{\externalfilterparameter\c!location}\v!paragraph
+ {\expanded{\checknextindentation[\externalfilterparameter\c!indentnext]}%
+ \dorechecknextindentation}
+ \endgroup
\stoptexdefinition
%D \subsubject {Execute Filter}
\starttexdefinition externalfilter@execute_filter
\processcommacommand[\externalfilterparameter{\c!filter\c!setups}]\directsetup
- \externalfilter@show_filtercommand
+ \iftraceexternalfilters \externalfilter@show_filtercommand \fi
\doifelse{\externalfilterparameter\c!cache}\v!yes
{\doifelse{\externalfilterparameter\c!state}\v!stop
@@ -397,6 +407,7 @@
%D \subsubject {Read output}
\starttexdefinition externalfilter@read_processed_file
+ \externalfilter@show_filenames
\doif{\externalfilterparameter\c!read}\v!yes
{\doiffileelse{\externalfilter@output_file}
{\externalfilter@read_processed_file_indeed}
@@ -438,6 +449,7 @@
\c!style=,
\c!color=,
\c!indentnext=\v!auto,
+ \c!align=,
\c!setups=,
\c!continue=\v!no,
\c!cache=\externalfilterparameter\c!continue, % for backward compatibility
@@ -454,8 +466,10 @@
\def\externalfilterbasefile {\externalfilter@base_file}
\def\externalfilterinputfile {\externalfilter@input_file}
\def\externalfilteroutputfile{\externalfilter@output_file}
-\def\currentexternalfilter {\externalfilter@name}
+% t-syntax-groups still uses this.
+\def\externalfilter@name {\currentexternalfilter}
+\def\externalfilter@namespace {\????externalfilter}
% Default value
\def\externalfilter@input_file {}
\def\externalfilter@output_file{}
diff --git a/Master/texmf-dist/tex/context/third/filter/t-filter.mkiv b/Master/texmf-dist/tex/context/third/filter/t-filter.mkiv
index 3df7890d347..9bc9a9b5465 100644
--- a/Master/texmf-dist/tex/context/third/filter/t-filter.mkiv
+++ b/Master/texmf-dist/tex/context/third/filter/t-filter.mkiv
@@ -1,6 +1,6 @@
%D \module
%D [ file=t-filter,
-%D version=2012.05.16,
+%D version=2012.06.20,
%D title=\CONTEXT\ User Module,
%D subtitle=Filter,
%D author=Aditya Mahajan,
@@ -9,7 +9,7 @@
%D email=adityam <at> ieee <dot> org,
%D license=Simplified BSD License]
-\writestatus{loading}{Filter (ver: 2012.05.16)}
+\writestatus{loading}{Filter (ver: 2012.06.20)}
% For backward compatibility
\ifx\grabbufferdata\undefined \let\grabbufferdata \dostartbuffer \fi
@@ -58,7 +58,8 @@
\appendtoks
\externalfilter@show_status{defining filter : \currentexternalfilter}%
\doifinset{\externalfilterparameter\c!cache}{\v!yes,\v!force}
- {\expandafter\newcounter\csname\externalfilter@count\endcsname}%
+ {\ifcsname\externalfilter@count\endcsname \else
+ \expandafter\newcounter\csname\externalfilter@count\endcsname\fi}%
\setuevalue{\e!start\currentexternalfilter}{\externalfilter@start[\currentexternalfilter]}%
\setuvalue {\e!stop\currentexternalfilter}{\externalfilter@process_filter}%
\setuevalue{process\currentexternalfilter file}{\externalfilter@process_file[\currentexternalfilter]}%
@@ -78,6 +79,7 @@
\setinterfacemessage\m!externalfilter{missing} {output file missing}
\setinterfacemessage\m!externalfilter{missing_cache} {cached output file -- missing. Rerunning filter}
\setinterfacemessage\m!externalfilter{forbidden} {Fatal Error: Cannot use absolute path -- as directory}
+\setinterfacemessage\m!externalfilter{unwriteable} {Fatal Error: Cannot write to file --}
\setinterfacemessage\m!externalfilter{slash} {Appending / to directory -- }
\setinterfacemessage\m!externalfilter{reuse} {\c!state=\v!stop : Not running filter on file --}
@@ -143,7 +145,7 @@
\externalfilter@set_directory
- \edef\externalfilter@input_file{\locfilename{#3}}
+ \edef\externalfilter@input_file{\externalfilter@any_filename{#3}}
\splitfilename{#3}
%NOTE: \edef doesn not work because \splitoffname is not expandable
\def\externalfilter@base_file {\splitoffname}
@@ -248,7 +250,7 @@
\fi
% Finalization
\doifinset{\externalfilterparameter\c!cache}{\v!yes,\v!force}
- {\doglobal\expandafter\increment\csname\externalfilter@count\endcsname}
+ {\doglobal\incrementvalue\externalfilter@count}
\endgroup
\stoptexdefinition
@@ -298,7 +300,24 @@
\edef\externalfilter@get_directory{\externalfilter@get_directory/}}
\stoptexdefinition
+%D \subsubject {Check if file is writeable}
+\starttexdefinition externalfilter@check_writable #1
+
+ \ctxcommand{doifnot(file.is_writable("#1"))}
+ {\showmessage\m!externalfilter{unwriteable}{#1}
+ \batchmode
+ \errmessage{}
+ \normalend}
+\stoptexdefinition
+
+%D \subsubject {Find file name (with search in \usepath)}
+%D
+%D The `\locfilename` macro does not search in the path specified by `\usepath`.
+%D So, we define a macro that is based on `\readfile`.
+
+\def\externalfilter@any_filename#1%
+ {\ctxcommand{getreadfilename("any",".","#1")}}
%D \subsubject {Set file names}
%D
@@ -316,7 +335,6 @@
\doifsomething{\externalfilterparameter\c!name}
{\edef\externalfilter@buffer_name{\externalfilter@temp_prefix-\currentexternalfilter-\externalfilterparameter\c!name}}
-
\externalfilter@set_filenames_extras
\iftraceexternalfilters \externalfilter@show_filenames \fi
@@ -355,6 +373,7 @@
%
% but using this method we cannot save the file in another directory.
% So, we simply write the file in the current directory and then move it.
+ \externalfilter@check_writable \externalfilter@input_file
\savebuffer[\externalfilterparameter{\c!buffer\c!before},
\externalfilter@buffer_name,
\externalfilterparameter{\c!buffer\c!after}]
@@ -365,7 +384,6 @@
os.remove("\jobname-\externalfilter@id.\f!temporaryextension")
\stopluacode
-
\externalfilter@execute_filter
\externalfilter@read_processed_file
\iftraceexternalfilters \else
@@ -375,10 +393,10 @@
% Finalization
\doifinset{\externalfilterparameter\c!cache}{\v!yes,\v!force}
- {\doglobal\expandafter\increment\csname\externalfilter@count\endcsname}
+ {\doglobal\incrementvalue\externalfilter@count}
\doif{\externalfilterparameter\c!location}\v!paragraph
- {\expanded{\checknextindentation[\externalfilterparameter\c!indentnext]}
+ {\expanded{\checknextindentation[\externalfilterparameter\c!indentnext]}%
\dorechecknextindentation}
\endgroup
\stoptexdefinition
@@ -391,20 +409,23 @@
% in the next run.
\starttexdefinition externalfilter@execute_filter
+ \externalfilter@check_writable \externalfilter@output_file
\processcommacommand[\externalfilterparameter{\c!filter\c!setups}]\directsetup
\iftraceexternalfilters \externalfilter@show_filtercommand \fi
- \doifelse{\externalfilterparameter\c!cache}\v!yes
- {\doifelse{\externalfilterparameter\c!state}\v!stop
- {\showmessage\m!externalfilter{reuse}\externalfilter@input_file}
- {\doiffileelse{\externalfilter@output_file}
- {\ctxlua{job.files.run(\!!bs\externalfilter@input_file\!!es,
- \!!bs\externalfilterparameter\c!filtercommand\!!es)}}
- {\showmessage\m!externalfilter{missing_cache}\externalfilter@output_file
- \executesystemcommand
- {\externalfilterparameter\c!filtercommand}}}}
- {\executesystemcommand
- {\externalfilterparameter\c!filtercommand}}
+ \doifelsenothing{\externalfilter@input_file}
+ {\showmessage\m!externalfilter{missing}\externalfilter@input_file}
+ {\doifelse{\externalfilterparameter\c!cache}\v!yes
+ {\doifelse{\externalfilterparameter\c!state}\v!stop
+ {\showmessage\m!externalfilter{reuse}\externalfilter@input_file}
+ {\doiffileelse{\externalfilter@output_file}
+ {\ctxlua{job.files.run(\!!bs\externalfilter@input_file\!!es,
+ \!!bs\externalfilterparameter\c!filtercommand\!!es)}}
+ {\showmessage\m!externalfilter{missing_cache}\externalfilter@output_file
+ \executesystemcommand
+ {\externalfilterparameter\c!filtercommand}}}}
+ {\executesystemcommand
+ {\externalfilterparameter\c!filtercommand}}}
\stoptexdefinition
%D \subsubject {Read output}