in2lambda.filters.markdown.image_pathΒΆ

in2lambda.filters.markdown.image_path(image_name: str, tex_file: str) str | None[source]ΒΆ

Determines the absolute path to an image referenced in a tex_file.

Parameters:
  • image_name – The file name of the image e.g. example.png

  • tex_file – The TeX file that references the image.

Returns:

The absolute path to the image if it can be found. If not, it returns None.

Examples

>>> from in2lambda.filters.markdown import image_path
>>> import tempfile
>>> import os
>>> # Example TeX file with a subdirectory
>>> temp_dir = tempfile.mkdtemp()
>>> tex_file = os.path.join(temp_dir, 'test.tex')
>>> with open(tex_file, 'w') as f:
...     f.write("\\graphicspath{{./subdir1/}{./subdir2/}{./subdir3/}}")
51
>>> # Example image in a relative subdirectory
>>> sub_dir = os.path.join(temp_dir, 'subdir3')
>>> os.makedirs(sub_dir)
>>> with open(os.path.join(sub_dir, 'inside_folder.png'), 'w') as f:
...     pass
>>> image_path("inside_folder.png", tex_file) == os.path.join(temp_dir, 'subdir3', "inside_folder.png")
True
>>> # Absolute path provided
>>> image_path(os.path.join(temp_dir, 'subdir3', "inside_folder.png"), tex_file) == os.path.join(temp_dir, 'subdir3', "inside_folder.png")
True