ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] command to process CSV file (database module)
@ 2023-11-05 12:56 Pablo Rodriguez via ntg-context
  2023-11-05 18:00 ` [NTG-context] " Pablo Rodriguez via ntg-context
  0 siblings, 1 reply; 2+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2023-11-05 12:56 UTC (permalink / raw)
  To: ConTeXt users; +Cc: Pablo Rodriguez

Dear list,

These are the following first four lines of a CSV file:

,,
"About \LuaTeX\ and
\ConTeXt","about.pdf","https://www.pragma-ade.com/general/manuals/about.pdf"
"l2r, r2l: A Few
Tips","bidi.pdf","https://www.pragma-ade.com/general/manuals/bidi.pdf"
"Flowcharts","charts-mkiv.pdf",

Faking a command such as \cA, \cB and \cC (for contents of columns A, B
or C) I would like to create a source document with an enumeration that
contains:

  \doiftext{\cB}
    {\item {\em\cA}\attachment[file=\cB]%
      \doiftext{\cC}{ (also available at \cC)}.}

I would like to do that with the "database" module.

So far I have adapted the itemize environment, but I don't get the
contents for items right:

  \usemodule[database]

  \starttext

  \def\ItemContents#1#2#3{\doiftext{#2}
    {\item {\em #1}\attachment[file=#2]%
      \doiftext{#3}{ (also available at #3)}.}}

  \defineseparatedlist
     [test]
     [separator={,}, % tab
      quotechar={"}, % tab
      before={\startitemize[n]},after={\stopitemize},
      first={\ItemContents},last={.},
      left={\{},right={\}}]

  \processdatabasefile[test][context-documents.csv]

  \stoptext

I get an error about an unexpected symbol near "\" in the line of
"\processdatabasefile".

Could anyone enlighten me about what I am missing here?

Many thanks for your help,

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

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [NTG-context] Re: command to process CSV file (database module)
  2023-11-05 12:56 [NTG-context] command to process CSV file (database module) Pablo Rodriguez via ntg-context
@ 2023-11-05 18:00 ` Pablo Rodriguez via ntg-context
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2023-11-05 18:00 UTC (permalink / raw)
  To: Pablo Rodriguez via ntg-context; +Cc: Pablo Rodriguez

On 11/5/23 13:56, Pablo Rodriguez via ntg-context wrote:
> [...]
> I get an error about an unexpected symbol near "\" in the line of
> "\processdatabasefile".
>
> Could anyone enlighten me about what I am missing here?

Replying to myself, thanks to the wiki
(https://wiki.contextgarden.net/Commands_with_optional_arguments).

It seems that the command has to be defined as unexpanded, such as in:

  \setupinteraction[state=start]
  \setupattachments[method=hidden]
  \usemodule[database]

  \starttext

  \unexpanded\def\ItemContents#1#2#3{\doiftext{#2}
    {\item {\em #1}\attachment[file=#2, name=\currentitemnumber-#2]%
      \doiftext{#3}{ (also available at #3)}}}

  \defineseparatedlist
     [test]
     [separator={,},
      quotechar={"},
      before={\startitemize[n]},after={\stopitemize},
      first={\ItemContents},last={.},
      left={\{},right={\}}]

  \processdatabasefile[test][context-documents.csv]

  \stoptext

It is not clear for me why is this needed, but it might be one of the
many aspects of expansion that average users cannot understand from TeX.

Many thanks for your help,

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

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-05 18:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-05 12:56 [NTG-context] command to process CSV file (database module) Pablo Rodriguez via ntg-context
2023-11-05 18:00 ` [NTG-context] " Pablo Rodriguez via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).