groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating macro for inline placement of pdf images


From: Peter Schaffter
Subject: Re: Creating macro for inline placement of pdf images
Date: Mon, 14 Nov 2022 21:52:05 -0500
User-agent: Mutt/1.9.4 (2018-02-28)

Hans --

> What would be the best approach to create a macro which inserts a
> image inline?

I field this question a lot from mom users.  Here's the solution I
suggest.  It's mom-specific but should help.  Basically, you
create a diversion to hold the graphic, map the diversion to a
character with .char, then create a string that outputs the graphic
"character" with vertical and horizontal adjustments derived from
the depth and width of the graphic.

.\" Begin inline-graphic template
.
.TITLE "Inline graphic example
.PRINTSTYLE TYPESET
.\" PDFIMAGEs are collected for inclusion in the List of Figures,
.\" which we don't want for inline graphics.  The internal macro
.\" that handles collection is PDF_TARGET.
.
.\" Rename PDF_TARGET to something else.
.rn PDF_TARGET PDF_TARGET_OLD
.
.\" Re-define PDF_TARGET to execute the original only if the
.\" no-target flag hasn't been set.
.de PDF_TARGET
. if !\\n[no-target] .PDF_TARGET_OLD
..
.
.\" Step 1: Create a diversion to hold the graphic.
.di graphic:1
. nr width:1 20p \" image width, needed for string 'graphic:1'
. nr depth:1 24p \" image depth, needed for string 'graphic:1'
. nr no-target 1
. PDF_IMAGE -L penguin-small.pdf \n[width:1]u \n[depth:1]u
. rr no-target
.di
.
.\" Step 2: Map the diversion to a character.
.char \[graphic:1] \*[graphic:1]
.
.\" Step 3: Define a string incorporating the vertical
.\" raise amount and width of the graphic.
.ds graphic:1 \v'-\n[depth:1]u'\[graphic:1]\h'\n[width:1]u'
.
.START
.PP
Lorem ipsum \*[graphic:1] dolor sit amet.
.
.\" End inline-graphic template

I'm attaching a pdf of the template.

-- 
Peter Schaffter
https://www.schaffter.ca

Attachment: inline-graphic.pdf
Description: Adobe PDF document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]