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 ---