* Re: Set up external figure for particular image type
2022-07-12 18:11 ` Thangalin via ntg-context
@ 2022-07-12 19:01 ` Rik Kabel via ntg-context
2022-07-18 16:01 ` Thangalin via ntg-context
2022-07-12 19:07 ` Wolfgang Schuster via ntg-context
2022-07-12 22:33 ` Albert Krewinkel via ntg-context
2 siblings, 1 reply; 12+ messages in thread
From: Rik Kabel via ntg-context @ 2022-07-12 19:01 UTC (permalink / raw)
To: ntg-context; +Cc: Rik Kabel
[-- Attachment #1.1: Type: text/plain, Size: 1473 bytes --]
On 2022-07-12 14:11, Thangalin via ntg-context wrote:
> Thank you for the suggestion Hraban.
>
> The source comes from Markdown, which is converted to XML, then
> typeset using ConTeXt. There's no Markdown-specific mechanism to
> relate images to a particular external figure definition,
> unfortunately. All images use the same syntax and are treated the same
> way. The only part that differs is the file name extension (and header
> within the file).
>
> One possibility would be something like:
> |\setupexternalfigure[ width=1em, height=1em, order={svg,pdf,png,jpg},
> location={local,default,global}, ] \defineexternalfigure[png][
> width=\textwidth, height=\textheight, ] \unprotect
> \let\old_externalfigure=\externalfigure
> \tolerant\def\externalfigure[#1]#,[#2]#,[#3]{%
> \doifelseinstring{.png}{#1}{% \old_externalfigure[#1][png][#2]% }{%
> \doifelsefileexists{#1.png}{% \old_externalfigure[#1.png][png][#2]%
> }{% \old_externalfigure[#1][#2][#3]% }% }% } \protect |
> See: https://tex.stackexchange.com/a/650221/2148
>
> I was wondering if there was a simpler or a solution that's more the
> ConTeXt-way?
>
> Thanks again!
Assuming that Pandoc markdown is being used, you should be able to set
class attributes on each image. You can then associate external figure
definitions with specific classes, and process each individually.
(Pandoc user guide, link_attributes
<https://pandoc.org/MANUAL%202.html#extension-link_attributes>)
--
Rik
[-- Attachment #1.2: Type: text/html, Size: 4995 bytes --]
[-- Attachment #2: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Set up external figure for particular image type
2022-07-12 19:01 ` Rik Kabel via ntg-context
@ 2022-07-18 16:01 ` Thangalin via ntg-context
0 siblings, 0 replies; 12+ messages in thread
From: Thangalin via ntg-context @ 2022-07-18 16:01 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Thangalin
[-- Attachment #1.1: Type: text/plain, Size: 2871 bytes --]
Thanks, Rik.
Not using Pandoc. I was using Pandoc up until 2020:
https://dave.autonoma.ca/blog/2019/05/22/typesetting-markdown-part-1/
I've since authored KeenWrite <https://github.com/DaveJarvis/keenwrite>,
which uses flexmark-java <https://github.com/vsch/flexmark-java> to
generate XHTML documents from Markdown. The only additions I've made to the
library is to add support for Pandoc's annotation syntax (:::).
That said, I'm also a firm believer in not duplicating information. The
information (file name extension) is already available in the documents, so
adding a classification on top of the extension feels redundant.
Thanks for the suggestion!
On Tue, Jul 12, 2022 at 12:18 PM Rik Kabel via ntg-context <
ntg-context@ntg.nl> wrote:
>
> On 2022-07-12 14:11, Thangalin via ntg-context wrote:
>
> Thank you for the suggestion Hraban.
>
> The source comes from Markdown, which is converted to XML, then typeset
> using ConTeXt. There's no Markdown-specific mechanism to relate images to a
> particular external figure definition, unfortunately. All images use the
> same syntax and are treated the same way. The only part that differs is the
> file name extension (and header within the file).
>
> One possibility would be something like:
>
> \setupexternalfigure[
> width=1em,
> height=1em,
> order={svg,pdf,png,jpg},
> location={local,default,global},
> ]
> \defineexternalfigure[png][
> width=\textwidth,
> height=\textheight,
> ]
> \unprotect
> \let\old_externalfigure=\externalfigure
> \tolerant\def\externalfigure[#1]#,[#2]#,[#3]{%
> \doifelseinstring{.png}{#1}{%
> \old_externalfigure[#1][png][#2]%
> }{%
> \doifelsefileexists{#1.png}{%
> \old_externalfigure[#1.png][png][#2]%
> }{%
> \old_externalfigure[#1][#2][#3]%
> }%
> }%
> }\protect
>
> See: https://tex.stackexchange.com/a/650221/2148
>
> I was wondering if there was a simpler or a solution that's more the
> ConTeXt-way?
>
> Thanks again!
>
>
> Assuming that Pandoc markdown is being used, you should be able to set
> class attributes on each image. You can then associate external figure
> definitions with specific classes, and process each individually. (Pandoc
> user guide, link_attributes
> <https://pandoc.org/MANUAL%202.html#extension-link_attributes>)
>
> --
> Rik
>
>
> ___________________________________________________________________________________
> 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
>
> ___________________________________________________________________________________
>
[-- Attachment #1.2: Type: text/html, Size: 6259 bytes --]
[-- Attachment #2: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Set up external figure for particular image type
2022-07-12 18:11 ` Thangalin via ntg-context
2022-07-12 19:01 ` Rik Kabel via ntg-context
@ 2022-07-12 19:07 ` Wolfgang Schuster via ntg-context
2022-07-18 17:10 ` Thangalin via ntg-context
2022-07-12 22:33 ` Albert Krewinkel via ntg-context
2 siblings, 1 reply; 12+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2022-07-12 19:07 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Wolfgang Schuster
[-- Attachment #1.1: Type: text/plain, Size: 2247 bytes --]
Thangalin via ntg-context schrieb am 12.07.2022 um 20:11:
> Thank you for the suggestion Hraban.
>
> The source comes from Markdown, which is converted to XML, then
> typeset using ConTeXt. There's no Markdown-specific mechanism to
> relate images to a particular external figure definition,
> unfortunately. All images use the same syntax and are treated the same
> way. The only part that differs is the file name extension (and header
> within the file).
>
> One possibility would be something like:
> |\setupexternalfigure[ width=1em, height=1em, order={svg,pdf,png,jpg},
> location={local,default,global}, ] \defineexternalfigure[png][
> width=\textwidth, height=\textheight, ] \unprotect
> \let\old_externalfigure=\externalfigure
> \tolerant\def\externalfigure[#1]#,[#2]#,[#3]{%
> \doifelseinstring{.png}{#1}{% \old_externalfigure[#1][png][#2]% }{%
> \doifelsefileexists{#1.png}{% \old_externalfigure[#1.png][png][#2]%
> }{% \old_externalfigure[#1][#2][#3]% }% }% } \protect |
> See: https://tex.stackexchange.com/a/650221/2148
>
> I was wondering if there was a simpler or a solution that's more the
> ConTeXt-way?
When you use XML as input you can add additional code to the setups block
which uses \externalfigure to load the image.
\setupexternalfigures [location={local,global,default}]
\defineexternalfigure [jpg] [width=4cm]
\defineexternalfigure [png] [width=8cm]
\starttexdefinition includegraphics #1
\splitfilename{#1}
\processaction
[\splitofftype]
[ jpg=>{\externalfigure[#1][jpg]},
png=>{\externalfigure[#1][png]},
default=>{\externalfigure[#1]},
unknown=>{\externalfigure[#1]}]
\stoptexdefinition
%\starttexdefinition includegraphics #1
%
% \getfiguredimensions[#1]
%
% \processaction
% [\figurefiletype]
% [ jpg=>{\externalfigure[#1][jpg]},
% png=>{\externalfigure[#1][png]},
% default=>{\externalfigure[#1]},
% unknown=>{\externalfigure[#1]}]
%
%\stoptexdefinition
\starttext
\includegraphics{hacker.jpg}
\includegraphics{mill.png}
\includegraphics{cow.pdf}
\stoptext
Wolfgang
[-- Attachment #1.2: Type: text/html, Size: 5402 bytes --]
[-- Attachment #2: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Set up external figure for particular image type
2022-07-12 19:07 ` Wolfgang Schuster via ntg-context
@ 2022-07-18 17:10 ` Thangalin via ntg-context
2022-07-18 20:14 ` Wolfgang Schuster via ntg-context
0 siblings, 1 reply; 12+ messages in thread
From: Thangalin via ntg-context @ 2022-07-18 17:10 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Thangalin
[-- Attachment #1.1: Type: text/plain, Size: 875 bytes --]
Thank you, Wolfgang.
That looks promising.
SVG files are converted using MetaPost. I thought the following would work:
svg=>{\externalfigure[#1][svg][conversion=mp]}
Is there anything else that needs to happen to ensure SVG files are piped
through MetaPost?
Thanks again!
> \setupexternalfigures [location={local,global,default}]
>
> \defineexternalfigure [jpg] [width=4cm]
> \defineexternalfigure [png] [width=8cm]
>
> \starttexdefinition includegraphics #1
>
> \splitfilename{#1}
>
> \processaction
> [\splitofftype]
> [ jpg=>{\externalfigure[#1][jpg]},
> png=>{\externalfigure[#1][png]},
> default=>{\externalfigure[#1]},
> unknown=>{\externalfigure[#1]}]
>
> \stoptexdefinition
>
> \starttext
>
> \includegraphics{hacker.jpg}
>
> \includegraphics{mill.png}
>
> \includegraphics{cow.pdf}
>
> \stoptext
>
>
[-- Attachment #1.2: Type: text/html, Size: 1968 bytes --]
[-- Attachment #2: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Set up external figure for particular image type
2022-07-18 17:10 ` Thangalin via ntg-context
@ 2022-07-18 20:14 ` Wolfgang Schuster via ntg-context
2022-08-01 0:29 ` Thangalin via ntg-context
0 siblings, 1 reply; 12+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2022-07-18 20:14 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Wolfgang Schuster
[-- Attachment #1.1: Type: text/plain, Size: 508 bytes --]
Thangalin via ntg-context schrieb am 18.07.2022 um 19:10:
> Thank you, Wolfgang.
>
> That looks promising.
>
> SVG files are converted using MetaPost. I thought the following would
> work:
>
> svg=>{\externalfigure[#1][svg][conversion=mp]}
You can probably remove the second argument ([svg]) which was used in my
example to pass the default values with \defineexternalfigure. Just
using \externalfigure[#1][conversion=mp] where you pass the default
values with the second argument is enough.
Wolfgang
[-- Attachment #1.2: Type: text/html, Size: 1374 bytes --]
[-- Attachment #2: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Set up external figure for particular image type
2022-07-18 20:14 ` Wolfgang Schuster via ntg-context
@ 2022-08-01 0:29 ` Thangalin via ntg-context
2022-08-01 7:07 ` Hans Hagen via ntg-context
0 siblings, 1 reply; 12+ messages in thread
From: Thangalin via ntg-context @ 2022-08-01 0:29 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Thangalin
[-- Attachment #1.1: Type: text/plain, Size: 854 bytes --]
Got it working. Complete solution:
\setupexternalfigures[
location={local,global,default},
width=\textwidth
]\defineexternalfigure[svg][width=1cm]\defineexternalfigure[jpg][width=2cm]\defineexternalfigure[png][width=4cm]
% Won't be applied because there's no process action.% Default
(\textwidth) is used, as defined
above.\defineexternalfigure[pdf][width=6cm]
\starttexdefinition includegraphics #1
\splitfilename{#1}
\processaction[\splitofftype][
jpg=>{\externalfigure[#1][jpg]},
png=>{\externalfigure[#1][png]},
svg=>{\externalfigure[#1][svg][conversion=mp]},
default=>{\externalfigure[#1]},
unknown=>{\externalfigure[#1]}
]\stoptexdefinition
\starttext
\includegraphics{kitten.jpg}
\includegraphics{mill.png}
\includegraphics{cow.pdf}
\includegraphics{tiger.svg}\stoptext
Image files attached.
Thanks again!
[-- Attachment #1.2: Type: text/html, Size: 2760 bytes --]
[-- Attachment #2: graphics.zip --]
[-- Type: application/zip, Size: 96638 bytes --]
[-- Attachment #3: Type: text/plain, Size: 496 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Set up external figure for particular image type
2022-08-01 0:29 ` Thangalin via ntg-context
@ 2022-08-01 7:07 ` Hans Hagen via ntg-context
0 siblings, 0 replies; 12+ messages in thread
From: Hans Hagen via ntg-context @ 2022-08-01 7:07 UTC (permalink / raw)
To: Thangalin via ntg-context; +Cc: Hans Hagen
On 8/1/2022 2:29 AM, Thangalin via ntg-context wrote:
> Got it working. Complete solution:
>
> |\setupexternalfigures[ location={local,global,default},
> width=\textwidth ] \defineexternalfigure[svg][width=1cm]
> \defineexternalfigure[jpg][width=2cm]
> \defineexternalfigure[png][width=4cm] % Won't be applied because there's
> no process action. % Default (\textwidth) is used, as defined above.
> \defineexternalfigure[pdf][width=6cm] \starttexdefinition
> includegraphics #1 \splitfilename{#1} \processaction[\splitofftype][
> jpg=>{\externalfigure[#1][jpg]}, png=>{\externalfigure[#1][png]},
> svg=>{\externalfigure[#1][svg][conversion=mp]},
> default=>{\externalfigure[#1]}, unknown=>{\externalfigure[#1]} ]
> \stoptexdefinition \starttext \includegraphics{kitten.jpg}
> \includegraphics{mill.png} \includegraphics{cow.pdf}
> \includegraphics{tiger.svg} \stoptext |
I've added:
\setfigureconversion[svg][mp]
So that this works:
\starttext
\externalfigure[kitten.jpg][width=2cm]
\externalfigure[mill.png] [width=4cm]
\externalfigure[cow.pdf] [width=6cm]
\externalfigure[tiger.svg] [width=1cm]
\stoptext
But after we release you need to wikify 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Set up external figure for particular image type
2022-07-12 18:11 ` Thangalin via ntg-context
2022-07-12 19:01 ` Rik Kabel via ntg-context
2022-07-12 19:07 ` Wolfgang Schuster via ntg-context
@ 2022-07-12 22:33 ` Albert Krewinkel via ntg-context
2022-07-18 16:03 ` Thangalin via ntg-context
2 siblings, 1 reply; 12+ messages in thread
From: Albert Krewinkel via ntg-context @ 2022-07-12 22:33 UTC (permalink / raw)
To: ntg-context; +Cc: Albert Krewinkel
Thangalin via ntg-context <ntg-context@ntg.nl> writes:
> The source comes from Markdown, which is converted to XML, then typeset
> using ConTeXt. There's no Markdown-specific mechanism to relate images
> to a particular external figure definition, unfortunately. All images
> use the same syntax and are treated the same way. The only part that
> differs is the file name extension (and header within the file).
The below is likely overkill and a good bit of work to setup, but it is
also very flexible. Maybe it suits your needs.
The Markdown-to-XML conversion can be tuned to include all the relevant
information. E.g., you could use pandoc with a custom writer to produce
the XML format of your choice. The link below is an example XML writer
that can be tuned as needed.
<https://gist.github.com/tarleb/634b409be0af62ca210cc9e96d41ca8c>
With that setup, one can modify the `Image` function to produce the
output you need. E.g., match on the file name extension use the library
function `pandoc.path.split_extension` and then change the element type
depending on the extension.
This way you'd have all the important information in your XML.
More info: <https://pandoc.org/custom-writers> and
<https://pandoc.org/lua-filters>.
Of course, you could also use pandoc to go directly to ConTeXt; that is
currently my preferred way of producing PDF from Markdown.
Cheers,
Albert
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 12+ messages in thread