From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/115476 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Wolfgang Schuster via ntg-context Newsgroups: gmane.comp.tex.context Subject: Re: Set up external figure for particular image type Date: Tue, 12 Jul 2022 21:07:34 +0200 Message-ID: References: <545a6de4-c8a6-b97f-7196-a4000bbdc65f@fiee.net> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0879754801458484532==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26475"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 PostboxApp/7.0.56 Cc: Wolfgang Schuster To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Jul 12 21:08:09 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 1oBLEu-0006VB-4f for gctc-ntg-context-518@m.gmane-mx.org; Tue, 12 Jul 2022 21:08:08 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 13CF4281B94; Tue, 12 Jul 2022 21:07:41 +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 Lw9_m9EkkuL6; Tue, 12 Jul 2022 21:07:38 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id AFF492854C1; Tue, 12 Jul 2022 21:07:38 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id B2735281B94 for ; Tue, 12 Jul 2022 21:07:36 +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 nzPhB2nfRAub for ; Tue, 12 Jul 2022 21:07:35 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.218.43; helo=mail-ej1-f43.google.com; envelope-from=wolfgang.schuster.lists@gmail.com; receiver= Original-Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 56CF42802E5 for ; Tue, 12 Jul 2022 21:07:35 +0200 (CEST) Original-Received: by mail-ej1-f43.google.com with SMTP id va17so16067068ejb.0 for ; Tue, 12 Jul 2022 12:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=ueo9krQqr0TGWlvljqkCWCF05EiTtXhhhpcgUkx0eYs=; b=ZS3hFyX6q73TdzcPZ7UvshGHIsM81TBBHTfFecPhwNxI0jvgVIsTlSyE1Tn9ebjTPZ tlqGLc63kEIk42QjfSRk7njno5FV9YQ8Hg0dFGzNlbZLMd9B+zNiM0vADuQXl5fJtHjB dME35VJ5/K7FDJi8FKAogiJ51UMgO0CyJ+kv89StzdQAxNg/zUA0kPVKuQ+2LMHps63/ mpLiHKkfldm6kUzhGFPxtTDzR/xCrrY2051lGzI/mPXVYyoo0CLUd8DFDc+w6EXQx3Bc JXm+K6VbervEPuYcr3NvJUejlVA2ODUrtBB7pTguO91ENpWinc2N0+Gv1Odm5V8zrVLG l4+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=ueo9krQqr0TGWlvljqkCWCF05EiTtXhhhpcgUkx0eYs=; b=CsP9eLCbOy91TQzPS5fFcMUWgcFjjh/Nb0LLO/48ayupEeTwL2VokhN9nkY6IjsHpV +trsz9C39ExxKzyXZvR3qr7nHFI6Bb3SbNTcY6etb7dFpfjvWedaUufhpTeG7ojU6uQL P/vKQK7DAxwAy9xhu178Th11Sm87C2MVWMWYyyXOHQkD6VR4e0moimMgJiGgxEDqjMIw rM0t6pyk3QKmAgTpcsufZk249zYSH+MAl/jT0d5G6tvwuAfAH95tqp6YfqUAE8XAay71 j2fuOdrUyn7jMH8VaiP/PPQ5w/RmtGZv6Qbvn7tkuQUNcNd8bkoGRnuODXDnSi0SVK2y 6fgQ== X-Gm-Message-State: AJIora/rqHwHR6H2no5hRSqdrBH/+BjDVqgr9eiS1bXRuQ2rDo12Yf1v sw3m9Zx36ezL7SHa8w1nxkAUra6AbVY= X-Google-Smtp-Source: AGRyM1sZoD20BfhSUd2JXR/GWOnIjFlHflRwJtCBZuwvGT0cNWQAp4L23SP+fMcXlffkFlC8W2RvNg== X-Received: by 2002:a17:907:2c61:b0:72b:3a12:5121 with SMTP id ib1-20020a1709072c6100b0072b3a125121mr18602729ejc.52.1657652853902; Tue, 12 Jul 2022 12:07:33 -0700 (PDT) Original-Received: from ?IPv6:2a02:810d:a8bf:f874::fb39? ([2a02:810d:a8bf:f874::fb39]) by smtp.gmail.com with ESMTPSA id kw24-20020a170907771800b006fe8ac6bc69sm4114357ejc.140.2022.07.12.12.07.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2022 12:07:33 -0700 (PDT) In-Reply-To: Content-Language: en-US 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:115476 Archived-At: This is a multi-part message in MIME format. --===============0879754801458484532== Content-Type: multipart/alternative; boundary="------------84FD6B33B72462E415D8800A" Content-Language: en-US This is a multi-part message in MIME format. --------------84FD6B33B72462E415D8800A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------84FD6B33B72462E415D8800A Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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

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

--------------84FD6B33B72462E415D8800A-- --===============0879754801458484532== 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== --===============0879754801458484532==--