Discussion:
[NTG-context] Language dependency in environment-project file
Marco Patzer
2018-11-27 20:37:18 UTC
Permalink
Hi,

I do have a project structure with environment, project and component files.
The language of the individual documents is defined in the components using

\setupdocument
[language=sv]

The environment needs to adjust language-dependent settings. However, when the
environment file is read, the language is not specified, yet. In the past I've
used

\appendtoks


\to\everystarttext

and I belive it has worked that way. In any case, right now it doesn't. I have
attached a not-so-minimal example project.

How to set this up correctly? If possible I'd like to keep the language in the
document settings as shown above.

A nudge in the right direction appreciated.

Marco
Wolfgang Schuster
2018-11-27 20:41:52 UTC
Permalink
Post by Marco Patzer
Hi,
I do have a project structure with environment, project and component files.
The language of the individual documents is defined in the components using
\setupdocument
[language=sv]
The environment needs to adjust language-dependent settings. However, when the
environment file is read, the language is not specified, yet. In the past I've
used
\appendtoks

\to\everystarttext
and I belive it has worked that way. In any case, right now it doesn't. I have
attached a not-so-minimal example project.
How to set this up correctly? If possible I'd like to keep the language in the
document settings as shown above.
A nudge in the right direction appreciated.
\appendtoks
  \mainlanguage[\documentvariable{language}]%
%\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}%
\to \everysetupdocument

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
_____________________________________________________________________
Marco Patzer
2018-11-27 20:56:46 UTC
Permalink
On Tue, 27 Nov 2018 21:41:52 +0100
Post by Marco Patzer
Post by Marco Patzer
A nudge in the right direction appreciated.
\appendtoks
  \mainlanguage[\documentvariable{language}]%
%\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}%
\to \everysetupdocument
That's basically what I've done in my project file (te-proj.tex). At
least the code is supposed to do exactly that.

But even your solution doesn't work here. Did you try it in the
example project file?

Marco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
_____________________________
Wolfgang Schuster
2018-11-27 21:05:27 UTC
Permalink
Post by Marco Patzer
On Tue, 27 Nov 2018 21:41:52 +0100
Post by Marco Patzer
Post by Marco Patzer
A nudge in the right direction appreciated.
\appendtoks
  \mainlanguage[\documentvariable{language}]%
%\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}%
\to \everysetupdocument
That's basically what I've done in my project file (te-proj.tex). At
least the code is supposed to do exactly that.
But even your solution doesn't work here. Did you try it in the
example project file?
\startenvironment [*]

\startsetups [itemgroup:en]
  \setupitemgroup [itemize] [i]
\stopsetups

\startsetups [itemgroup:sv]
  \setupitemgroup [itemize] [a]
\stopsetups

\setuplanguage
  [en]
  [setups=itemgroup:en]

\setuplanguage
  [sv]
  [setups=itemgroup:sv]

\appendtoks
\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}
\to \everysetupdocument

\stopenvironment

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
____________________________________________________________________________
Marco Patzer
2018-11-27 21:23:26 UTC
Permalink
On Tue, 27 Nov 2018 22:05:27 +0100
Post by Wolfgang Schuster
Post by Marco Patzer
But even your solution doesn't work here. Did you try it in the
example project file?
\startenvironment [*]
\startsetups [itemgroup:en]
  \setupitemgroup [itemize] [i]
\stopsetups
\startsetups [itemgroup:sv]
  \setupitemgroup [itemize] [a]
\stopsetups
\setuplanguage
  [en]
  [setups=itemgroup:en]
\setuplanguage
  [sv]
  [setups=itemgroup:sv]
\appendtoks
\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}
\to \everysetupdocument
\stopenvironment
That works, thanks.

One more question: I used to use modes, since I could just

\startmode[*en]

\stopmode

any number of times. There are many language dependent settings in
the environment files.

With named setups I need to specify a name for each occurrence and
gather them at the end. This is not as clean. Is it possible e.g. to
add something to an already existing setup instead of creating a new
one every time?

Marco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________
Wolfgang Schuster
2018-11-27 21:41:25 UTC
Permalink
Post by Marco Patzer
On Tue, 27 Nov 2018 22:05:27 +0100
Post by Wolfgang Schuster
Post by Marco Patzer
But even your solution doesn't work here. Did you try it in the
example project file?
\startenvironment [*]
\startsetups [itemgroup:en]
  \setupitemgroup [itemize] [i]
\stopsetups
\startsetups [itemgroup:sv]
  \setupitemgroup [itemize] [a]
\stopsetups
\setuplanguage
  [en]
  [setups=itemgroup:en]
\setuplanguage
  [sv]
  [setups=itemgroup:sv]
\appendtoks
\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}
\to \everysetupdocument
\stopenvironment
That works, thanks.
One more question: I used to use modes, since I could just
\startmode[*en]

\stopmode
any number of times. There are many language dependent settings in
the environment files.
With named setups I need to specify a name for each occurrence and
gather them at the end. This is not as clean. Is it possible e.g. to
add something to an already existing setup instead of creating a new
one every time?
No, this is only possible with a token list.


\startenvironment [*]

\newtoks\EnglishSettings
\newtoks\SwedishSettings

\appendtoks
  \setupitemgroup [itemize] [i]
\to \EnglishSettings

\appendtoks
  \setupitemgroup [itemize] [a]
\to \SwedishSettings

% the order of the following settings is important because you have
% to set the language before you can make the language dependant
% mode setting

\appendtoks
\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}
\to \everysetupdocument

\appendtoks
  \startmodeset
    [**en] {\flushtoks\EnglishSettings}
    [**sv] {\flushtoks\SwedishSettings}
  \stopmodeset
\to \everysetupdocument

\stopenvironment


Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
____________________________________________
Marco Patzer
2018-11-28 07:38:06 UTC
Permalink
On Tue, 27 Nov 2018 22:41:25 +0100
Post by Wolfgang Schuster
Post by Marco Patzer
With named setups I need to specify a name for each occurrence and
gather them at the end. This is not as clean. Is it possible e.g. to
add something to an already existing setup instead of creating a new
one every time?
No, this is only possible with a token list.
Works perfectly.

Your first solution is technically better since it works even if the
language is changed mid document (something not used in this
project). However, the second solution is cleaner. I'll make up my mind.

Thanks for the quick help.

Marco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
_______________________________
Wolfgang Schuster
2018-11-28 21:17:48 UTC
Permalink
Post by Marco Patzer
On Tue, 27 Nov 2018 22:41:25 +0100
Post by Wolfgang Schuster
Post by Marco Patzer
With named setups I need to specify a name for each occurrence and
gather them at the end. This is not as clean. Is it possible e.g. to
add something to an already existing setup instead of creating a new
one every time?
No, this is only possible with a token list.
Works perfectly.
Your first solution is technically better since it works even if the
language is changed mid document (something not used in this
project). However, the second solution is cleaner. I'll make up my mind.
The solution with the token list would be nicer if there where a way
to store the content in a similar fashion as buffers (which allow adding
content but this requires Lua) or setups.


\unprotect

\installnamespace {tokenlist}

\unexpanded\def\definetokenlist[#1]%
  {\expandafter\newtoks\csname\????tokenlist#1\endcsname}

\unexpanded\def\starttokenlist[#1]#2\stoptokenlist
  {\ifcsname\????tokenlist#1\endcsname \else
     \expandafter\newtoks\csname\????tokenlist#1\endcsname
   \fi
   \expandafter\toksapp\csname\????tokenlist#1\endcsname{#2}}

\def\gettokenlist[#1]%
  {\ifcsname\????tokenlist#1\endcsname
     \expandafter\the\csname\????tokenlist#1\endcsname
   \fi}

% \unexpanded\def\definetokenlist[#1]%
%   {\expandafter\let\csname\????tokenlist#1\endcsname\empty}
%
% \unexpanded\def\starttokenlist[#1]#2\stoptokenlist
%   {\ifcsname\????tokenlist#1\endcsname \else
%      \expandafter\let\csname\????tokenlist#1\endcsname\empty
%    \fi
%    \expandafter\edef\csname\????tokenlist#1\endcsname
%
{\normalunexpanded\expandafter\expandafter\expandafter{\csname\????tokenlist#1\endcsname}%
%       \normalunexpanded\expandafter{#2}}}
%
% \def\gettokenlist[#1]%
%   {\ifcsname\????tokenlist#1\endcsname
%      \csname\????tokenlist#1\endcsname
%    \fi}

\protect

\starttext

% \definetokenlist[test]

\starttokenlist[test]
a
\stoptokenlist

b

\starttokenlist[test]
c
\stoptokenlist

\gettokenlist[test]

\stoptext


Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
_________________________________________________________
Wolfgang Schuster
2018-11-29 19:30:53 UTC
Permalink
Post by Marco Patzer
On Tue, 27 Nov 2018 22:41:25 +0100
Post by Wolfgang Schuster
Post by Marco Patzer
With named setups I need to specify a name for each occurrence and
gather them at the end. This is not as clean. Is it possible e.g. to
add something to an already existing setup instead of creating a new
one every time?
No, this is only possible with a token list.
Works perfectly.
Your first solution is technically better since it works even if the
language is changed mid document (something not used in this
project). However, the second solution is cleaner. I'll make up my mind.
Below is a improved version of the token method which works with the new
beta.


\startenvironment [*]

\definetokenlist [english] % optional because \starttokenlist
\definetokenlist [swedish] % checks if the token lists exists

\starttokenlist [english]
  \setupitemgroup [itemize] [i]
\stoptokenlist

\starttokenlist [swedish]
  \setupitemgroup [itemize] [a]
\stoptokenlist

\startsetups [document:start]

\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}

  \startmodeset
    [*en] {\gettokenlist[english]}
    [*sv] {\gettokenlist[swedish]}
  \stopmodeset

\stopsetups

\stopenvironment


Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
____________________________________________________
Marco Patzer
2018-11-29 20:57:41 UTC
Permalink
On Thu, 29 Nov 2018 20:30:53 +0100
Post by Wolfgang Schuster
Below is a improved version of the token method which works with the
new beta.
\startenvironment [*]
\definetokenlist [english] % optional because \starttokenlist
\definetokenlist [swedish] % checks if the token lists exists
\starttokenlist [english]
  \setupitemgroup [itemize] [i]
\stoptokenlist
\starttokenlist [swedish]
  \setupitemgroup [itemize] [a]
\stoptokenlist
\startsetups [document:start]
\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}
  \startmodeset
    [*en] {\gettokenlist[english]}
    [*sv] {\gettokenlist[swedish]}
  \stopmodeset
\stopsetups
\stopenvironment
So that's basically a glorified \appendtoks … \to\… using the
usual context syntax? Very neat.

Marco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________
Hans Hagen
2018-11-28 08:20:49 UTC
Permalink
Post by Wolfgang Schuster
Post by Marco Patzer
On Tue, 27 Nov 2018 21:41:52 +0100
Post by Marco Patzer
Post by Marco Patzer
A nudge in the right direction appreciated.
\appendtoks
    \mainlanguage[\documentvariable{language}]%
%\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}%
\to \everysetupdocument
That's basically what I've done in my project file (te-proj.tex). At
least the code is supposed to do exactly that.
But even your solution doesn't work here. Did you try it in the
example project file?
\startenvironment [*]
\startsetups [itemgroup:en]
  \setupitemgroup [itemize] [i]
\stopsetups
\startsetups [itemgroup:sv]
  \setupitemgroup [itemize] [a]
\stopsetups
\setuplanguage
  [en]
  [setups=itemgroup:en]
\setuplanguage
  [sv]
  [setups=itemgroup:sv]
\appendtoks
\doifdocumentvariable{language}{\mainlanguage[\documentvariable{language}]}
\to \everysetupdocument
\stopenvironment
An alternative is to use system modes:

\mainlanguage[nl]

% \startmode[*en]
% \setupitemize[n]
% \stopmode

% \startmode[*nl]
% \setupitemize[a]
% \stopmode

% \startmode[*de]
% \setupitemize[i]
% \stopmode

\startmodeset
[*en] {
\setupitemize[n]
}
[*nl] {
\setupitemize[a]
}
[*de] {
\setupitemize[i]
}
\stopmodeset

\starttext

\startitemize
\startitem test \stopitem
\startitem test \stopitem
\stopitemize

\stoptext

where modesets have a sort of special syntax (so probably only wolfgang
and i know that this one exists),

Hans


-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
_______________________________________________
Marco Patzer
2018-11-28 10:09:26 UTC
Permalink
On Wed, 28 Nov 2018 09:20:49 +0100
Post by Hans Hagen
\mainlanguage[nl]
% \startmode[*en]
% \setupitemize[n]
% \stopmode
% \startmode[*nl]
% \setupitemize[a]
% \stopmode
% \startmode[*de]
% \setupitemize[i]
% \stopmode
\startmodeset
[*en] {
\setupitemize[n]
}
[*nl] {
\setupitemize[a]
}
[*de] {
\setupitemize[i]
}
\stopmodeset
I do use modes and modesets in this project, but mainly in the
components. In the environment files it's a bit more tricky because
the language is unknown at this point and the system modes trigger
the wrong language. But Wolfgang already provided a solution, which
works fine.

Marco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-***@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
_____________________________________________
Loading...