asciidoctor / asciidoctor-mathematical

An extension for Asciidoctor that converts the content of STEM blocks and inline macros using Mathematical.
MIT License
49 stars 44 forks source link

Make imagesdir relative to source file not working directory #65

Closed dalemartin closed 4 years ago

dalemartin commented 4 years ago

Not sure if File::join is the best way, but this fixes an issue where nested documents broke the path to the stem/latexmath images when imagesdir is defined.

For example, you have this project file tree:

basedir/images/cat.png basedir/subdir/source.adoc

Assume source.adoc defines attributes as:

:imagesdir: ../../images
:imagesoutdir: {imagesdir}/equations/generated_images

In a large project, you want to run asciidoctor-pdf from the base directory using a wildcard to find all the files. The imagesdir attribute expands to its string ../../images, which is then interpreted as relative to the working directory from which asciidoctor-pdf was called, rather than the directory of the source file containing the attribute. I've appended imagesdir the docdir attribute so that it is always interpreted from the point of view that it was declared.

I've never programmed in Ruby before, so I had trouble referencing the join_path method from the path_resolver.rb class, but maybe that would be more desirable than File::join?

dalemartin commented 4 years ago

There's actually more to this... there are other broken cases if imagesdir or imagesoutdir aren't defined.

dalemartin commented 4 years ago

Created a more thorough fix in #70