From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/115509 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thangalin via ntg-context Newsgroups: gmane.comp.tex.context Subject: Re: Set up external figure for particular image type Date: Mon, 18 Jul 2022 09:01:13 -0700 Message-ID: References: <545a6de4-c8a6-b97f-7196-a4000bbdc65f@fiee.net> <995e8fc7-b8ea-3d87-92e8-b2dd8aa8f1e4@rik.users.panix.com> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4159600567883791107==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37254"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Thangalin To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Mon Jul 18 18:04:08 2022 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDTE7-0009MX-VH for gctc-ntg-context-518@m.gmane-mx.org; Mon, 18 Jul 2022 18:04:07 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id A05B12A3C00; Mon, 18 Jul 2022 18:01:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N9dkZx9loxK5; Mon, 18 Jul 2022 18:01:29 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id ACEBB2A3C05; Mon, 18 Jul 2022 18:01:28 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id B36A52A3C00 for ; Mon, 18 Jul 2022 18:01:26 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pY296sgNdKD1 for ; Mon, 18 Jul 2022 18:01:25 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.208.179; helo=mail-lj1-f179.google.com; envelope-from=thangalin@gmail.com; receiver= Original-Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 38B262A3BFE for ; Mon, 18 Jul 2022 18:01:25 +0200 (CEST) Original-Received: by mail-lj1-f179.google.com with SMTP id w2so14143701ljj.7 for ; Mon, 18 Jul 2022 09:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Ahpkypu6cMliQ30OjDSPnrtn/YUlImVVtYUoZyYDYn4=; b=fLij7lAZbLfV/Kwi604QeW9mAvv9eDWqtUlWRfZQEgufrIvJMImxs/XpHeMJ9vIg4I emilNSLd48sxSDDwnG1FWSHGR0RhQi/VhFuBpAQn0HJ4U0s5tIlGFghDgDeymTXmwe5H vx5ToADKWYeTNX+39lzpcRk8M0Y0PA6pifVk4+yo2zojPrqAJmR6J31yDvdAJ5IQlKC5 iYjA+wsoTvfhBTC0N0sR957uL9rArefrsH7imXL7sh6phqIZHF/xBEKGlTHvjHE/QhLC mmo9FR9c7RNnBVnwcSZHgKhrr0M0mEBUQfiUPRjv4Ya2bEjeNnPjvPWgq+bkwj4m3Khi e4Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Ahpkypu6cMliQ30OjDSPnrtn/YUlImVVtYUoZyYDYn4=; b=EyWD/rX+f6EuFSv8V9YSBamqLlDavODdbCeJkcsSaPE615xPoPI1m4XhD7OslOnKdn 9cZ9Le3JcQtxe90RVhY5wtnkT0ZWe2X7d6V4izBof3rdslnib6zrpf+3P1dlIq8CCZqK ca3nOWpz7JMc0AlJP1hJc4/aW0geQOWenIWMUdAJOikfNmm/2+JW2du2Qabv06EQY8Ge 119vjHzwKcBSP01yVVlCtWUIzoNJKbyWW/RMm0EmHEHHpcfdN8CRrvqLWnIHMCNBRcLy +9pi9IsyW5snXZljV3Dpq6N/RDWrQ4Dx2DV1gMmb2OPKolG+RSDxkz//0gYeucReVRMT v9Vw== X-Gm-Message-State: AJIora+rhw20O2gZU2NbexRueebW5G+/TzN2M+MuqS4KZ4Jm8ben4sN8 BZ0Ebs2wZ8Ls7Pju8e6dLuBY1jVnDJ+FIudY2nI16vEmhNI= X-Google-Smtp-Source: AGRyM1uCIuq4Bjf2KRylkF9y5V31UGEDNHA45Z5qUT4kUmpDE1IyEzQubP7+BEtMZYsckgZdzsHZzDku9GY8vKkTZsI= X-Received: by 2002:a2e:b7d5:0:b0:25d:5320:ebad with SMTP id p21-20020a2eb7d5000000b0025d5320ebadmr12877975ljo.56.1658160084523; Mon, 18 Jul 2022 09:01:24 -0700 (PDT) In-Reply-To: <995e8fc7-b8ea-3d87-92e8-b2dd8aa8f1e4@rik.users.panix.com> X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:115509 Archived-At: --===============4159600567883791107== Content-Type: multipart/alternative; boundary="000000000000d19d3705e4167a41" --000000000000d19d3705e4167a41 Content-Type: text/plain; charset="UTF-8" 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 , which uses 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 > ) > > -- > 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 > > ___________________________________________________________________________________ > --000000000000d19d3705e4167a41 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Tha= nks, Rik.

<= /div>
Not using Pando= c. I was using Pandoc up until 2020:


I'v= e since authored KeenWr= ite, which uses flexm= ark-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 (:::).
<= br>
That said, = I'm also a firm believer in not duplicating information. The informatio= n (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:
=20 =20 =20


On 2022-07-12 14:11, Thangalin via ntg-context wrote:
=20
Thank you fo= r 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=3D1em,
    height=3D1em,
    order=3D{svg,pdf,png,jpg},
    location=3D{local,default,global},
]

\defineexternalfigure[png][
    width=3D\textwidth,
    height=3D\textheight,
]

\unprotect

\let\old_externalfigure=3D\ext=
ernalfigure

\tolerant\def\externalfigure[#=
1]#,[#2]#,[#3]{<=
span>%
    \doifelseinstring{.png}{#1}{%
        \old_externalfigure[#1][png]=
[#2]%
    }{%
        \doifelsefileexists{#1.png}{%
            \old_externalfigure[#1.p=
ng][png][#2]%
        }{%
            \old_externalfigure[#1][=
#2][#3]%
        }%
    }%
}
\protect

I was wondering if there was a simpler or a solution that's more th= e ConTeXt-way?

Thanks again!
=C2=A0

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)

--
Rik


___________________________________________________________________________= ________
If your question is of interest to others as well, please add an entry to t= he Wiki!

maillist : ntg-cont= ext@ntg.nl / https://www.ntg.nl/mailman/listinfo/= ntg-context
webpage=C2=A0 : https://www.pragma-ade.nl / http://context.aanhet.net
archive=C2=A0 :
https://bitbucket.org/phg/context-m= irror/commits/
wiki=C2=A0 =C2=A0 =C2=A0: https://contextgarden.net
___________________________________________________________________________= ________
--000000000000d19d3705e4167a41-- --===============4159600567883791107== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cHM6Ly93d3cubnRnLm5sL21haWxtYW4v bGlzdGluZm8vbnRnLWNvbnRleHQKd2VicGFnZSAgOiBodHRwczovL3d3dy5wcmFnbWEtYWRlLm5s IC8gaHR0cDovL2NvbnRleHQuYWFuaGV0Lm5ldAphcmNoaXZlICA6IGh0dHBzOi8vYml0YnVja2V0 Lm9yZy9waGcvY29udGV4dC1taXJyb3IvY29tbWl0cy8Kd2lraSAgICAgOiBodHRwczovL2NvbnRl eHRnYXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============4159600567883791107==--