Usage of filename in document
Hi List, is there a way in conTeXt how I can use a filename, so that I can write a text where I can refer to it for using it in the following scenario: I need 4 documents with nearly the same content. what I like to do is to switch in the document depending on the called filename. as I got a file called invoice.tex and create some links to this file called delivery.tex order.tex and so on and now call texexec invoice.tex or texexec order.tex I want the document to recognize in the first case that it is invoice and in the second case that it is order, so that I can use an if then else environment on the different parts where I can define the following if{filename==invoice} then{print this content} else{} if{filename==order} then{print this part of content} else{} Thanks for your help. Greetings Martin
Martin,
Martin Scholz
is there a way in conTeXt how I can use a filename, so that I can write a text where I can refer to it for using it in the following scenario:
I need 4 documents with nearly the same content. what I like to do is to switch in the document depending on the called filename.
as I got a file called invoice.tex and create some links to this file called delivery.tex order.tex and so on and now call
texexec invoice.tex
or
texexec order.tex
I want the document to recognize in the first case that it is invoice and in the second case that it is order, so that I can use an if then else environment on the different parts where I can define the following
if{filename==invoice} then{print this content} else{} if{filename==order} then{print this part of content} else{}
Have you looked at modes? I use this technique for making manuscript, presentation and speakernotes versions of teaching documents. Here is an example: %%% TheEarthWorks.tex --- %% Author: rmason@mun.ca %% Version: $Id: TheEarthWorks.tex,v 0.0 2009/01/14 19:16:14 rmason Exp$ % Styles specific to the pres and MS modes: \input presentation.tex \input manuscript.tex \starttext \startcolor[TextColor] \setupalign[right, nothyphenated] \setuptolerance[horizontal,verytolerant] % Title \titlepage{Gems, The Earth \& its Works} % ----------------------------------------------------------------------------- \NewSlide{Diamonds are a girls best friend} \oneplot{fig:intro}{Diamonds are a girls best friend\ldots and tell us a lot about how the Earth works.}{\externalfigure[Brillanten]} % reference caption image \startmode[manuscript] \section{Introduction} The Earth is made of rocks and in turn the rocks are made of minerals. Most gems (\in{Fig.}[fig:intro]) are minerals. We will look at rocks and minerals soon, but before we do so it is useful to have an overview of the bigger picture: the structure of the Earth. We will then go on to look at how various kinds of rocks are formed before focusing on minerals and gems. \stopmode%[manuscript] \startmode[manuscript] \section{Structure of the Earth} What is the interior of the Earth like? Is it structureless, like Christmas cake, or does it have a structure, like layer cake? If the Earth is structureless then maybe gems can form and be found anywhere. If it has structure then perhaps specific gems form only in particular places. \stopmode%[manuscript] % ----------------------------------------------------------------------------- \NewSlide{Structure of the Earth} \twoplots % reference caption % image1 caption1 % image2 caption2 {fig:cakes}{What is the structure of the earth?} {\externalfigure[Stirring_christmas_pudding]}{Christmas pudding?} % http://en.wikipedia.org/wiki/Image:Stirring\_christmas\_pudding.JPG % No licensing info given. {\externalfigure[Layer_cake]}{Layer cake?} % http://kitchen-delights.blogspot.com/2007/10/ % iced-lemon-curd-layer-cake.html} % Licensing conditions not known. \startmode[manuscript] Various lines of evidence show that Earth is a layered planet (\in{Fig.}[fig:earthstructure]). The outermost layer is the \emph{crust}, which is made largely of rocks and minerals that have low density. \stopmode%[manuscript] % ----------------------------------------------------------------------------- \NewSlide{Earth Structure} \oneplot{fig:earthstructure}{Internal structure of the Earth}{\externalfigure[Earth_structure]} % reference caption image % http://en.wikipedia.org/wiki/Image:Earth-crust-cutaway-english.svg Surachit % Original png was public domain. No license info for this svg version \startmode[presentation] % ----------------------------------------------------------------------------- \NewSlide{Where are gems found?} \onewideplot{fig:gemsfound}{Where are gems found?}{\externalfigure[Crust]} % reference caption image % ----------------------------------------------------------------------------- \NewSlide{Where are gems formed?} \onewideplot{fig:gemsformed}{Where are gems formed?}{\externalfigure[Crust_upper_mantle.jpg]} % reference caption image \stopmode%[presentation] \startmode[manuscript] The next layer inwards is the \emph{mantle} which occupies a large portion of the volume of the Earth and is made of rocks and minerals with a density around twice that of the crust. Beneath the mantle is the core, which is subdivided into the \emph{outer core}, which is liquid and the \emph{inner core} which is solid. The core has a density about twice that of the mantle. The layering then is by {\em density} and it increases as the centre of the Earth is approached. Tha majority of gems are found, and originated in, the crust (\in{Fig.}[fig:earthstructure]). Diamonds are an exception, having been formed in the upper mantle. The gemstone {\em peridot} (a form of the mineral {\em olivine}) can also be formed in the mantle and incorporated in the crust in the form of \emph{peridotite} inclusions that are brought up in some volcanic eruptions. There is no evidence that material from the core reaches the Earth's surface. However, we do have material similar to the material of the core in the form of {\em iron} and \emph{stony-iron} meteorites (\in{Fig.}[fig:meteorites]). Fewer than 100 stony-irons are known and they are commercially and scientifically valuable. The ``stony'' component is olivine, often peridot quality. The iron component is an iron-nickel alloy. \stopmode%[manuscript] The \input *.tex documents contain definitions used in the text. The document is then compiled using a command: texexec --mode=manuscript --result=EarthWorksMS.pdf TheEarthWorks.tex When i want the presentation version I just change to --mode=presentation on the command line. Cheers, Roger
Am Thu, 05 Nov 2009 17:28:08 -0330 schrieb Roger Mason:
Martin,
Martin Scholz
writes: is there a way in conTeXt how I can use a filename, so that I can write a text where I can refer to it for using it in the following scenario:
I need 4 documents with nearly the same content. what I like to do is to switch in the document depending on the called filename.
as I got a file called invoice.tex and create some links to this file called delivery.tex order.tex and so on and now call
texexec invoice.tex
or
texexec order.tex
I want the document to recognize in the first case that it is invoice and in the second case that it is order, so that I can use an if then else environment on the different parts where I can define the following
if{filename==invoice} then{print this content} else{} if{filename==order} then{print this part of content} else{}
Have you looked at modes? I use this technique for making manuscript, presentation and speakernotes versions of teaching documents.
Here is an example:
%%% TheEarthWorks.tex ---
%% Author: rmason@mun.ca %% Version: $Id: TheEarthWorks.tex,v 0.0 2009/01/14 19:16:14 rmason Exp$
% Styles specific to the pres and MS modes: \input presentation.tex \input manuscript.tex
\starttext \startcolor[TextColor] \setupalign[right, nothyphenated] \setuptolerance[horizontal,verytolerant]
% Title \titlepage{Gems, The Earth \& its Works}
%
-----------------------------------------------------------------------------
\NewSlide{Diamonds are a girls best friend} \oneplot{fig:intro}{Diamonds are a girls best friend\ldots and tell us a lot about how the Earth works.}{\externalfigure[Brillanten]} % reference caption image
\startmode[manuscript] \section{Introduction} The Earth is made of rocks and in turn the rocks are made of minerals. Most gems (\in{Fig.}[fig:intro]) are minerals. We will look at rocks and minerals soon, but before we do so it is useful to have an overview of the bigger picture: the structure of the Earth. We will then go on to look at how various kinds of rocks are formed before focusing on minerals and gems. \stopmode%[manuscript]
\startmode[manuscript] \section{Structure of the Earth} What is the interior of the Earth like? Is it structureless, like Christmas cake, or does it have a structure, like layer cake? If the Earth is structureless then maybe gems can form and be found anywhere. If it has structure then perhaps specific gems form only in particular places. \stopmode%[manuscript]
%
-----------------------------------------------------------------------------
\NewSlide{Structure of the Earth} \twoplots % reference caption % image1 caption1 % image2 caption2 {fig:cakes}{What is the structure of the earth?} {\externalfigure[Stirring_christmas_pudding]}{Christmas pudding?} % http://en.wikipedia.org/wiki/Image:Stirring\_christmas\_pudding.JPG % No licensing info given. {\externalfigure[Layer_cake]}{Layer cake?} % http://kitchen-delights.blogspot.com/2007/10/ % iced-lemon-curd-layer-cake.html} % Licensing conditions not known.
\startmode[manuscript] Various lines of evidence show that Earth is a layered planet (\in{Fig.}[fig:earthstructure]). The outermost layer is the \emph{crust}, which is made largely of rocks and minerals that have low density. \stopmode%[manuscript]
%
-----------------------------------------------------------------------------
\NewSlide{Earth Structure} \oneplot{fig:earthstructure}{Internal structure of the Earth}{\externalfigure[Earth_structure]} % reference caption image % http://en.wikipedia.org/wiki/Image:Earth-crust-cutaway-english.svg Surachit % Original png was public domain. No license info for this svg version
\startmode[presentation] %
-----------------------------------------------------------------------------
\NewSlide{Where are gems found?} \onewideplot{fig:gemsfound}{Where are gems found?}{\externalfigure[Crust]} % reference caption image
%
-----------------------------------------------------------------------------
\NewSlide{Where are gems formed?} \onewideplot{fig:gemsformed}{Where are gems formed?}{\externalfigure[Crust_upper_mantle.jpg]} % reference caption image \stopmode%[presentation]
\startmode[manuscript] The next layer inwards is the \emph{mantle} which occupies a large portion of the volume of the Earth and is made of rocks and minerals with a density around twice that of the crust. Beneath the mantle is the core, which is subdivided into the \emph{outer core}, which is liquid and the \emph{inner core} which is solid. The core has a density about twice that of the mantle. The layering then is by {\em density} and it increases as the centre of the Earth is approached.
Tha majority of gems are found, and originated in, the crust (\in{Fig.}[fig:earthstructure]). Diamonds are an exception, having been formed in the upper mantle. The gemstone {\em peridot} (a form of the mineral {\em olivine}) can also be formed in the mantle and incorporated in the crust in the form of \emph{peridotite} inclusions that are brought up in some volcanic eruptions.
There is no evidence that material from the core reaches the Earth's surface. However, we do have material similar to the material of the core in the form of {\em iron} and \emph{stony-iron} meteorites (\in{Fig.}[fig:meteorites]). Fewer than 100 stony-irons are known and they are commercially and scientifically valuable. The ``stony'' component is olivine, often peridot quality. The iron component is an iron-nickel alloy. \stopmode%[manuscript]
The \input *.tex documents contain definitions used in the text. The document is then compiled using a command:
texexec --mode=manuscript --result=EarthWorksMS.pdf TheEarthWorks.tex
When i want the presentation version I just change to --mode=presentation on the command line.
Cheers, Roger
Hi Roger, List Thanks that sounds ok, but now I need to know I can use this by an external program, as I try to build a letter for Lx-Office, an OpenSource ERP Programm that uses TeX for processing the output and I can not really switch in it the type how it is called, so I need more or less an indocument version for this, like the if-then-else-clauses so thanks but I think it is not the way I can use it. Greetings Martin
Hi Roger, List
Thanks that sounds ok, but now I need to know I can use this by an external program, as I try to build a letter for Lx-Office, an OpenSource ERP Programm that uses TeX for processing the output and I can not really switch in it the type how it is called, so I need more or less an indocument version for this, like the if-then-else-clauses so thanks but I think it is not the way I can use it.
\expandafter\convertargument\jobname\to\testablejobname \expandafter\convertargument mkii\to\Myjobname \doif{mkii}{\testablejobname} { mkii } you need to do this conversion first as jobname has funny catcodes Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am Thu, 05 Nov 2009 22:18:54 +0100 schrieb Hans Hagen:
Hi Roger, List
Thanks that sounds ok, but now I need to know I can use this by an external program, as I try to build a letter for Lx-Office, an OpenSource ERP Programm that uses TeX for processing the output and I can not really switch in it the type how it is called, so I need more or less an indocument version for this, like the if-then-else-clauses so thanks but I think it is not the way I can use it.
\expandafter\convertargument\jobname\to\testablejobname \expandafter\convertargument mkii\to\Myjobname
\doif{mkii}{\testablejobname} { mkii }
you need to do this conversion first as jobname has funny catcodes
Hans
Hi Hans, thanks will try it and see how it works, really fascinated about conTeXt, is a great work and I really like it also I just started to use it and am a real newbe in using it. Greetings Martin
Martin Scholz wrote:
Hi List,
is there a way in conTeXt how I can use a filename, so that I can write a text where I can refer to it for using it in the following scenario:
I need 4 documents with nearly the same content. what I like to do is to switch in the document depending on the called filename.
as I got a file called invoice.tex and create some links to this file called delivery.tex order.tex and so on and now call
texexec invoice.tex
or
texexec order.tex
I want the document to recognize in the first case that it is invoice and in the second case that it is order, so that I can use an if then else environment on the different parts where I can define the following
if{filename==invoice} then{print this content} else{} if{filename==order} then{print this part of content} else{}
why not use modes: \doifmode{invoice} { ... } and texexec whatever.tex --mode=invoice Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Thu, 5 Nov 2009, Martin Scholz wrote:
is there a way in conTeXt how I can use a filename, so that I can write a text where I can refer to it for using it in the following scenario:
I need 4 documents with nearly the same content. what I like to do is to switch in the document depending on the called filename.
Hello Martin, As already posted, modes are good for binary switches. Often, I extract some values from the filename, that are used in the text, here is a simple example: \def\ResultName{\systemparameter{file}} % only to show, that a special filename can trigger a mode: \doif{\ResultName}{order}{\enablemode[ordermode]}{} \starttext This file is the \ResultName. \startmode[ordermode] special text for order \stopmode \stoptext Then I call context with different resultnames: "context --result=order filename" or "context --result=invoice filename"
as I got a file called invoice.tex and create some links to this file called delivery.tex order.tex and so on and now call
Symbolic links are a good idea, if you cannot submit options like "--result=...". Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
participants (4)
-
Hans Hagen
-
Martin Scholz
-
Peter Münster
-
Roger Mason