[tex4ht] How to \includegraphics using absolute path with tex4ht?

Nasser M. Abbasi nma at 12000.org
Sun Oct 8 13:12:18 CEST 2023


On 10/8/2023 5:38 AM, Nasser M. Abbasi wrote:
> Is there a way to make copy_images adjust the "src=" automatically
> to new copy location?
> 

I think there is a better solution to all of this. no need
to copy images and do any of this.

There are tools that automatically converts absolute path to relative path.
I only use Linux to build.

https://stackoverflow.com/questions/2564634/convert-absolute-path-into-relative-path-given-a-current-directory-using-bash
https://unix.stackexchange.com/questions/522012/how-to-convert-absolute-path-to-relative-path

and so on.

So given the example I have

\includegraphics[width=textwidth]{/mnt/g/public_html/my_notes/images/my_image}

If make4ht can detect that the image path is absolute (i.e. it starts with /),
and since current directory is always known "." then it can do

     realpath --relative-to=. /mnt/g/public_html/my_notes/images/my_image

To automatically generate relative path and use that in the src= for the image
which could look now something like

   src="../../my_notes/images/my_image.svg"

as an example. I just tried it on a real path and it works

---------------------
>pwd
/mnt/g/public_html/my_notes/solving_ODE/current_version/TESTS/bad_title

>realpath --relative-to=.  /mnt/g/public_html/my_notes/solving_ODE/current_version/images/king_billingham_otto_2003.svg

../../images/king_billingham_otto_2003.svg
---------------------

May be even lua can be used to automatically convert absolute path in
\includegraphics to relative one?

\includegraphics[width=textwidth]{/mnt/g/public_html/my_notes/images/my_image}

to

\includegraphics[width=textwidth]{../../my_notes/images/my_image}

This will solve all the problem.

Thanks,
--Nasser



More information about the tex4ht mailing list.