On Wed, Nov 05, 2025 at 08:08:37PM +0000, Gavin Smith wrote:
> I've tested this with Emacs 29.3 and it is required for the "math" keyword
> to be at the end: the following doesn't work:
> 
>    ^@^H[image math src="test_info_math2img3.png" text="a + b"^@^H]
> 

After researching this more, I find that Info mode recognizes this as
long as extra attributes are in the ATTRIBUTE=VALUE format.  Comment
from info.el:

   (defun Info-split-parameter-string (parameter-string)
     "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
   PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
   If VALUE contains whitespace or double quotes, it must be quoted
   in double quotes and any double quotes or backslashes must be
   escaped (\\\",\\\\)."
     (let ((start 0)

So something like the following does work:

    ^@^H[image command=math src="test_info_math2img3.png" text="a + b"^@^H]

I'm not proposing this, though, just stating it as a possibility.
           
We could add attributes giving the below-baseline-depth and the DPI
generation setting.  It happens that dvipng has a --depth option
which prints this depth in pixels:

'--depth*'
     Report the depth of the image.  This only works reliably when the
     LaTeX style 'preview.sty' from preview-latex is used with the
     'active' option.  It reports the number of pixels from the bottom
     of the image to the baseline of the image.  This can be used for
     vertical positioning of the image in, e.g., web documents...

(from the dvipng Info manual).
           
The "preview-latex" manual is rather obscure on how to get the required
dimensions:

    For most applications, you'll want to make use of the ‘tightpage’
  option.  This will embed the page dimensions into the PostScript or PDF
  code, obliterating the need to use the ‘-E -i’ options to Dvips.  You
  can then produce all image files with a single run of Ghostscript from a
  single PDF or PostScript (as opposed to EPS) file.
  
     Various options exist that will pass TeX dimensions and other
  information about the respective shipped out material (including
  descender size) into the log file, where external applications might
  make use of it.

(Info node "(preview-latex)The LaTeX style file".)
           
I found this old email saying something about the "DVI specials"
that preview-latex put into the .dvi file:

  From: David Kastrup
  Subject:      Re: [AUCTeX] Preview: baselines and dvi specials
  Date: Mon, 06 Oct 2008 17:32:04 +0200

  > I'm trying to use the preview package for taking latex equations and
  > converting them to svg through dvi. There are a lot of drivers that
  > produce svg files, but I can't find one that produces baseline
  > information. Dvipng, on the other hand, does give baseline
  > information.
  >
  > My understanding is that the tightpage option spits out dvi specials
  > and this is how dvipng computes its baseline. Is this right?
  
  Pretty much.
  
  > I'm looking at specials like the following:
  >
  > ps::-32891 -32891 32891 32891 521949 0 945438
  >
  > Can anyone tell me how to interpret these numbers?
  
  They are measured in scaled points (1pt/65536).  Basically, they are the
  same numbers that are reported on the console if you pass the "lyx"
  option to preview.

https://lists.gnu.org/archive/html/auctex/2008-10/msg00016.html
           
The documentation for dvips documents the ps special as a way to put
raw PostScript into a dvi file:

  Generally, Dvips encloses specials in a PostScript save/restore pair,
  guaranteeing that the special will have no effect on the rest of the
  document.  The 'ps' special, however, allows you to insert literal
  PostScript instructions without this protective shield; you should
  understand what you're doing (and you shouldn't change the PostScript
  graphics state unless you are willing to take the consequences).  This
  command can take many forms because it has had a torturous history; any
  of the following will work:
  
       \special{ps:TEXT}
       \special{ps::TEXT}
       \special{ps::[begin]TEXT}
       \special{ps::[end]TEXT}
       \special{ps::[nobreak]TEXT}
  
  (with longer forms taking precedence over shorter forms, when they are
  present).  'ps::' and 'ps::[end]' do no positioning, so they can be used
  to continue PostScript literals started with 'ps:' or 'ps::[begin]'.

(Info node "(dvips)ps special".)

However, it is just a list of numbers, so I'm not really sure how that
functions as PostScript code.

So I haven't got very far in understanding exactly how latex-preview/AUCTeX
or dvipng works, but can trust that they do the right thing between them.
We could put the output from dvipng --depth as the value of a "depth"
attribute.  For example, here's some sample output for a test file I
was experimenting with:

$ dvipng -T tight -D 180 --depth test_info_math2img.dvi
This is dvipng 1.15 Copyright 2002-2015 Jan-Ake Larsson
[1 (preview-latex version 13.2) (preview-latex tightpage option detected, will 
use its bounding box) depth=2] [2 depth=10] [3 depth=2] 

It should be simple to extract the depth values from such output and use them
in the Info output.  For example, the third image could be output as:

  ^@^H[image src="test_info_math2img3.png" dpi=180 depth=2 text="a + b"^@^H]

The only other possible information to be added is the nominal text size for 
TeX,
as Patrice pointed out on his email on the 8th January:

> Otherwise said, if we give the DPI information, I think that we should
> also give the 10pt (10/72.27 in) information.









Reply via email to