[NTG-context] [m-database] How to properly add module arguments?

2023-02-25 Thread Paul Mazaitis via ntg-context
Dear list,

## The Incredibly Short Version

I am trying to extend m-database, and I want to add a flag to control behavior. 
I can get it to work, but I am having trouble understanding how to do it 
properly.

## The Short Version

I have a project where I wish to incorporate many CSV files as Natural Tables.

I want to keep the headers in the CSV files so they're useful in other contexts.

The `m-database` module doesn't have a feature to suppress the header row, from 
what I can see.

(I know `handlecsv` can do this, but I'm having troubles with that; if the 
`m-database` line of inquiry doesn't work out, I'll go back it, but I figure 
I'll focus on this solution for now.)

Looking at the module sources, I can implement the functionality I need in the 
Lua part of the module, but:

I seem to only be able to bodge in additional arguments for the commands in the 
module.

On first try, I got the error: `tex error   > tex error on line 30 in file 
/Users/pmazaitis/Opt/context/tex/texmf-context/tex/context/modules/mkiv/m-databaseplus.mkiv:
 ! Undefined control sequence`

And then: `The control sequence at the end of the top line of your error 
message was never
\def'ed.`

Looking at the docs points me to a solution using  `\def`, but it's not clear 
to me how that's working in the case of the database module (the database 
module seems to be initializing these values someplace else?).

If I \def the settings variable in m-database.mkiv,  I can get it to work, but 
I don't think that's the correct way to go about this.

Question: how do I properly define new module arguments for the database module?

## The Long Version, With MWE

### Files Associated With the MWE

Apologies for all of the file inclusions, but I want to be complete.


Here's the .csv file I'm using for the MWE:

--- begin database-mwe.csv ---

Ref. No.,Part No.,Description,Remarks
,RD14C82E000J,Carbon 000흮 ±5% 1/4W,

---  end database-mwe.csv  ---

Some notes on database-mwe.csv:

I'd like to keep the header row in place to make this file useful for other 
tools.

These are lists of electronic parts, so I'd like to include uppercase omega, 
lower case mu, and percent sign characters in the CSV file.


Here's the .tex file I'm using for the MWE:

--- begin database-mwe.tex ---

\usemodule[database]

\setupdatabase[quotechar={"},separator={,}]

\defineseparatedlist
  [PartsTable]
  [separator=comma,left=\bTD,right=\eTD,first=\bTR,last=\eTR,before={
\bTABLE[split=repeat,option=stretch]
  \bTABLEhead
  \bTR
\bTH Ref. No. \eTH \bTH Part No. \eTH \bTH Description \eTH \bTH Remarks 
\eTH
  \eTR
  \eTABLEhead
  \bTABLEbody
   },
   after={
  \eTABLEbody
  \eTABLE
   }]

\starttext

test

\startasciimode
\processdatabasefile[PartsTable][parts_list-test.csv]
\stopasciimode

\stoptext

---  end database-mwe.tex  ---

Some notes on database-mwe.tex:

This actually works pretty well with the distributed m-database module!

Some of these lists are quite long, so I want to use a TABLEhead to replicate 
the headings at the top of a new page. I don't think there's a way to automate 
this with `m-database`, so I'm okay with hard-coding the headers. This does 
mean I get a double header row at the top of the table. I want to suppress the 
header row; I'd like to implement this behavior in the module behind a switch.

(I'm using the `asciimode` environment to dodge problems with unescaped `%` 
characters and Greek letters. I tried adding the startasciimode/stopasciimode 
commands to various keys in the \defineseparatedlist command, but I didn't get 
anywhere with it - I got errors. A problem for another time...)

I think I've got a good handle on how to do this in Lua, but I'm struggling 
with what to add to the switch appropriately.

In attempting to add a switch, I tried the following.

Based off of https://wiki.contextgarden.net/Modules#Modules_writing_guidelines,
I added a stanza to the appropriate interface file:

--- begin stanza added to i-database.xml ---






---  end stanza added to i-database.xml  ---

I modeled that after the stanza for the argument `strip`. I think that's the 
only thing I need to do in the interface file.

Changing the i-database.xml file does not break the build.

However, as soon as I add the skipheader argument to the m-database.mkiv file:

--- begin definition in m-database.mkiv ---

\setupdatabase
  [\c!separator={,},
   \c!quotechar=,
   \c!commentchar=,
   \c!strip=\v!no,
   \c!skipheader=\v!no, % <- Added, following the pattern with strip
   \c!before=,
   \c!after=,
   \c!first=,
   \c!last=,
   \c!left=,
   \c!right=]

---  end definition in m-database.mkiv  ---


...the build fails (with the error from the Short Version section).

If I then add the following \def to m-database.mkiv before the \setupdatabase 
command:

\def\c!skipheader {skipheader}

...the build succeeds! I can now pass that settings value to m-database.lua and 
use it 

Re: [NTG-context] Can ConTeXt display a simple itemized list as a comma-separated list?

2023-02-25 Thread Hans Hagen via ntg-context

On 2/25/2023 5:01 PM, Joel via ntg-context wrote:

I have a list like this:

\startitemize[1]
\item fish
\item eggs
\item milk
\stopitemize

Is there any command in ConTeXt to make this display the items as a 
comma-separated list, like this:


fish, eggs, milk

Or a semi-colon-separated list?

fish; eggs; milk
it's not that hard to add a few lines to the core to support that, so 
i'll look into it


-
  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-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


[NTG-context] Can ConTeXt display a simple itemized list as a comma-separated list?

2023-02-25 Thread Joel via ntg-context
I have a list like this:
\startitemize[1]\item fish\item eggs\item milk\stopitemize
Is there any command in ConTeXt to make this display the items as a 
comma-separated list, like this:
fish, eggs, milk
Or a semi-colon-separated list?
fish; eggs; milk
--Joel
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] structureuservariable as list

2023-02-25 Thread Alex Leray via ntg-context

Dear both,

thanks for your answers.

`doloopovermatch` didn't work for me but this below is achieving what I 
wanted.


Have a good day,

Alex

%%%

\def\dosomething#1{(#1)}

\def\dosomethingtwo#1{* #1\crlf}

\starttext
\startchapter[title={Foo Bar}][
authors={Alice,Bob,Charline},
translators={foo,bar,baz}
]

{\em authors} \\
\commalistsentence[\structureuservariable{authors}][{ \crlf },{ \crlf }]

{\em translators} \\
\processcommacommand[\structureuservariable{translators}]\dosomethingtwo

\doloopoverlist {\structureuservariable{translators}} {
 (#1) \\
}

\stopchapter
\stoptext

%%%

Le 25/02/23 à 11:08, Hans Hagen via ntg-context a écrit :

On 2/24/2023 11:37 PM, Rik Kabel via ntg-context wrote:



Hi,

is it possible to pass a list in a variable? I'd like to pass a list 
of authors:



\startchapter[title={Foo Bar}][authors={Alice, Bob}]

% PSEUDOCODE
% for author in \structureuservariable{authors}
% do print(author + '\crlf')
% done

\stopchapter


Search the wiki. Look for "Comma Separated Lists." There is a variant 
with an author list as an example.


You may need additional brace levels around the list entries.

I'm not sure this is on the wiki ...

\starttext

\startchapter[title={Foo Bar}][authors={Alice, Bob},AUTHORS={Bob,Alice}]

     \doloopovermatch {[^, ]+} {\structureuservariable{authors}}  {
     (#1)\crlf
     }
     \doloopovermatch {[^,]+} {\structureuservariable{authors}}  {
     (#1)\crlf
     }
     \doloopovermatch {[^,]+} {\structureuservariable{AUTHORS}}  {
     (#1)\crlf
     }
     \doloopovermatch {[^,]+} {\structureuservariable{AUTHORS}}  {
     \doloopovermatch {.} {#1}  {
     (##1)
     }
     \crlf
     }

\stopchapter

but feel free to add it.

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-context@ntg.nl / 
https://www.ntg.nl/mailman/listinfo/ntg-context

webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


--
Alexandre Leray
+32 487 947 030

Avez-vous pensé à (vous) offrir Médor ?
https://medor.coop/ideescadeau
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] structureuservariable as list

2023-02-25 Thread Hans Hagen via ntg-context

On 2/24/2023 11:37 PM, Rik Kabel via ntg-context wrote:



Hi,

is it possible to pass a list in a variable? I'd like to pass a list 
of authors:



\startchapter[title={Foo Bar}][authors={Alice, Bob}]

% PSEUDOCODE
% for author in \structureuservariable{authors}
% do print(author + '\crlf')
% done

\stopchapter


Search the wiki. Look for "Comma Separated Lists." There is a variant 
with an author list as an example.


You may need additional brace levels around the list entries.

I'm not sure this is on the wiki ...

\starttext

\startchapter[title={Foo Bar}][authors={Alice, Bob},AUTHORS={Bob,Alice}]

\doloopovermatch {[^, ]+} {\structureuservariable{authors}}  {
(#1)\crlf
}
\doloopovermatch {[^,]+} {\structureuservariable{authors}}  {
(#1)\crlf
}
\doloopovermatch {[^,]+} {\structureuservariable{AUTHORS}}  {
(#1)\crlf
}
\doloopovermatch {[^,]+} {\structureuservariable{AUTHORS}}  {
\doloopovermatch {.} {#1}  {
(##1)
}
\crlf
}

\stopchapter

but feel free to add it.

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-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___