Difference between revisions of "Command/ReadFile"

From Wiki
Jump to navigation Jump to search
(Created page with "Documentation for \ReadFile")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<cd:commandgroup name="ReadFile" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807">
 
<cd:commandgroup name="ReadFile" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807">
 
<cd:shortdesc><!-- a short command summary goes here -->
 
<cd:shortdesc><!-- a short command summary goes here -->
The command <tt>\ReadFile</tt> is used for ...
+
The command <tt>\ReadFile</tt> includes an external file
 
</cd:shortdesc>
 
</cd:shortdesc>
 
<cd:variants>
 
<cd:variants>
Line 8: Line 8:
 
     <cd:keywords delimiters="braces" ordinal="1">
 
     <cd:keywords delimiters="braces" ordinal="1">
 
     <cd:keywordsdoc></cd:keywordsdoc>
 
     <cd:keywordsdoc></cd:keywordsdoc>
     <cd:constant type="cd:file"></cd:constant>
+
     <cd:constant type="cd:file">name of the file</cd:constant>
 
     </cd:keywords>
 
     </cd:keywords>
 
   </cd:arguments>
 
   </cd:arguments>
 
   </cd:command>
 
   </cd:command>
 
</cd:variants>
 
</cd:variants>
<cd:description><!-- the long description of the command goes here -->
+
<cd:description>The command <code>\ReadFile {filename}</code> is replaced by the content of the text file <code>filename</code>, if it exists. If it does not exist, no error message is generated and the compile process continues.
 +
 
 +
When no file extension is specified, the extension <code>.tex</code> is assumed.
 +
 
 +
Similar to the case with project structure commands such as {{cmd|environment}}, {{cmd|ReadFile}} causes ConTeXt to look in ancestor directories for the specified file.
 +
 
 
</cd:description>
 
</cd:description>
<cd:examples></cd:examples>
+
<cd:examples><cd:example title="">We have a chapter 1 file, but no chapter 2 file:
 +
<texcode>
 +
% chapter-01.tex
 +
\subject{Chapter 1}
 +
 
 +
This is the first chapter.
 +
</texcode>
 +
 
 +
The book file attempts to incorporate both chapters, using <code>\ReadFile{filename}</code>:
 +
<texcode>
 +
% complete-book.tex
 +
\starttext
 +
 
 +
% No extension specified, so .tex assumed
 +
\ReadFile{chapter-01}
 +
\ReadFile{chapter-02}
 +
 
 +
\stoptext
 +
</texcode>
 +
 
 +
Compiling <code>book.tex</code> produces the following:
 +
 
 +
<context>
 +
\subject{Chapter 1}
 +
 
 +
This is the first chapter.
 +
</context>
 +
 
 +
No error message is generated for the missing chapter 2, and the compilation completes successfully.
 +
</cd:example></cd:examples>
 
<cd:notes></cd:notes>
 
<cd:notes></cd:notes>
 
<cd:seealso>
 
<cd:seealso>
 
<cd:source file="file-res.mkvi" originator="system"></cd:source>
 
<cd:source file="file-res.mkvi" originator="system"></cd:source>
<cd:wikipage originator="system" page="Category:Structure"></cd:wikipage></cd:seealso>
+
<cd:wikipage originator="system" page="Category:Structure"></cd:wikipage>
 +
<cd:commandref name="input">Similar to <code>\ReadFile</code> but the filename is not specified as an argument.</cd:commandref>
 +
<cd:commandref name="readfile">Similar to <code>\ReadFile</code> with additional options when file is not found.</cd:commandref>
 +
<cd:commandref name="getbuffer">Get back the "formatted" content of a buffer. </cd:commandref>
 +
<cd:commandref name="typebuffer">Get back the content of a buffer as verbatim text.</cd:commandref>
 +
<cd:commandref name="typefile">Print a file verbatim</cd:commandref>
 +
<cd:commandref name="component">for input command with more descriptive name.</cd:commandref>
 +
<cd:commandref name="environment">for input command with more descriptive name.</cd:commandref>
 +
<cd:wikipage page="Dummy text">for ways to produce filler text</cd:wikipage>
 +
<cd:wikipage page="Category:Projects"></cd:wikipage>
 +
<cd:wikipage page="Category:Internals"></cd:wikipage></cd:seealso>
 
</cd:commandgroup>
 
</cd:commandgroup>

Latest revision as of 08:23, 1 November 2021


\ReadFile

Summary

The command \ReadFile includes an external file

Settings

\ReadFile{...}
{...}file

OptionExplanation
file name of the file

Description

The command \ReadFile {filename} is replaced by the content of the text file filename, if it exists. If it does not exist, no error message is generated and the compile process continues.

When no file extension is specified, the extension .tex is assumed.

Similar to the case with project structure commands such as \environment, \ReadFile causes ConTeXt to look in ancestor directories for the specified file.


Examples

Example 1

We have a chapter 1 file, but no chapter 2 file:

% chapter-01.tex
\subject{Chapter 1}

This is the first chapter.

The book file attempts to incorporate both chapters, using \ReadFile{filename}:

% complete-book.tex
\starttext

% No extension specified, so .tex assumed
\ReadFile{chapter-01}
\ReadFile{chapter-02}

\stoptext

Compiling book.tex produces the following:

No error message is generated for the missing chapter 2, and the compilation completes successfully.

Notes

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: