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: hbezemer
Subject: Re: Creating macro for inline placement of pdf images
Date: Wed, 16 Nov 2022 12:41:21 +0100
User-agent: s-nail v14.9.24

Dear all,

After some thinkering I came up with this macro:
.de INLINE
.ec @
.sy pdfinfo @$1 | \
grep -a "Page *size" | \
sed -e 's/Page *size: *\\([[:digit:].]*\\) *x *\\([[:digit:].]*\\).*$/\
.nr in-wid (p;\\1)\\n\
.nr in-ht  (p;\\2)/' \
> /tmp/pdfpicA
.so /tmp/pdfpicA
.sy rm /tmp/pdfpicA
.ec
.sy echo ".ds Breed $(echo 'scale=2; \\n[in-wid]/\\n[in-ht]*\\n[.ps]/1000' | bc
-l)"p > /tmp/pdffac
.so /tmp/pdffac
.sy rm /tmp/pdffac
\v'-\\n[.ps]u'
\X'pdf: pdfpic \\$1 0p \\*[Breed]'
\h'\\*[Breed]'
..
I've used a part of pdfpic.tmac to calculate the height and width of the pdf. 
The height of the pdf is scaled to the value of \n[.ps].
That way, when altering the pointsize the pdf is scaled accordingly.

At first I tried to lower the pdf a bit, this results in unexpected behaviour of
the remaining part of the sentence (either to low or to high, but it can't be
adjusted to match the preceeding part of the sentence).
I don't now why this happens, lowering a character with any amount of space and
moving back up to the starting position works all the time.
Maybe it has to do with the \X'pdf: pdfpic...' command.

Anyways, it seems to work fine now.

Hans

hbezemer--- via <groff@gnu.org> wrote:

> Dear Peter,
> 
> Thank you for your eloborate answer.
> I will look into it and give a heads up when I got it working.
> 
> Regards!
> 
> Hans
> 
> Peter Schaffter <peter@schaffter.ca> wrote:
> 
> > 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



reply via email to

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