Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect rendering of latex piecewise functions. #521

Closed
dbraun31 opened this issue Jan 3, 2023 · 3 comments
Closed

Incorrect rendering of latex piecewise functions. #521

dbraun31 opened this issue Jan 3, 2023 · 3 comments
Labels
bug Something isn't working resolved
Milestone

Comments

@dbraun31
Copy link

dbraun31 commented Jan 3, 2023

I've noticed that latex piecewise functions don't seem to render correctly when converting from md to html (this is the workflow I mentioned in the previous issue I raised #506 where I'm not actually using Obsidian but just using obsidianhtml to convert standard md).

Example: The following latex

$$
v(x) = \begin{cases}
    x^{\alpha} & \text{if } x \geq 0 \\
    -\lambda \cdot (-x)^{\alpha} & \text{if } x < 0
    \end{cases}
$$

should be rendered in the html as

v_correct

but is instead being rendered as

v_incorrect

See here for a live html with more examples. These changes are up to date on my project repo (md is here).

I thought maybe the issue was being caused by incorrect parsing of the double forward slash \\, but as you'll see on my html I tested general multi line equations and it renders correctly. The issue best I can tell is restricted to piecewise functions wrapped in the \begin{cases} environment.

Let me know if I can provide any other helpful info.

dwrolvink added a commit to dwrolvink/obsidian-html that referenced this issue Jan 3, 2023
dwrolvink added a commit that referenced this issue Jan 3, 2023
@dwrolvink
Copy link
Collaborator

Wow that was a very subtle bug.
I tracked it down to some weird interaction happening because the latex was not treated as a codeblock, thus some parsing actions were applied to it.

I've changed this so that the latex blocks are stripped from the document when altering it, and they are put back right before converting the markdown to html.

This has solved the issue for me, and quite possibly will solve a myriad of other potential latex bugs that you or others might have had.

Let me know if this works for you. (Install master)

@dbraun31
Copy link
Author

dbraun31 commented Jan 3, 2023

Yup, that fix worked.

But this new master branch is less tolerant of my workaround when using <img /> tags for images. When converting with the following config

# The first folder that contains all obsidian files
# Use full path or relative path, but don't use ~/
# obsidian_folder_path_str: '/home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/md/' 
obsidian_folder_path_str: '/home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/md/'

# The note that will be used as the index.html 
# should be in obsidian_folder_path_str
# Use full path or relative path, but don't use ~/
obsidian_entrypoint_path_str: '/home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/md/homepage.md'

html_url_prefix: '/gaita/ideation/structured/html'

toggles:
  process_all: True

I get

DEPRECATION WARNING: The setting obsidian_folder_path_str is deprecated. See https://obsidian-html.github.io/Configurations/Deprecated%20Configurations/Deprecated%20Configurations.html for more information.
> COPYING VAULT /home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/md TO /tmp/tmpwctm7h4b
running: 
	 rsync -a /home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/md/ /tmp/tmpwctm7h4b --exclude /.obsidian --exclude /.trash --exclude /.DS_Store --exclude /.git
Copy succeeded 0  b''
< COPYING VAULT: Done
> CLEARING OUTPUT FOLDERS
> CREATING OUTPUT FOLDERS
> COMPILING MARKDOWN FROM OBSIDIAN CODE (/tmp/tmpwctm7h4b/homepage.md)
	> FEATURE: PROCESS ALL
	< FEATURE: PROCESS ALL: Done
> COMPILING HTML FROM MARKDOWN CODE (/home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/to_html/output/md/index.md)

	OBS.HTML EXTRA ERROR INFORMATION:
	---------------------------------
	Current action              : Conversion of markdown notes to html notes
	Subroutine                  : crawl_markdown_notes_and_convert_to_html
	Current note being processed: /home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/to_html/output/md/experiment-2-theory.md ()

Traceback (most recent call last):
  File "/home/dave/.local/lib/python3.10/site-packages/obsidianhtml/core/ErrorHandling.py", line 60, in _decorator
    res = f(*args, **kwargs)
  File "/home/dave/.local/lib/python3.10/site-packages/obsidianhtml/controller/ConvertVault.py", line 756, in crawl_markdown_notes_and_convert_to_html
    lo.copy_file('mth')
  File "/home/dave/.local/lib/python3.10/site-packages/obsidianhtml/core/FileObject.py", line 252, in copy_file
    shutil.copyfile(src_file_path, dst_file_path)
  File "/usr/lib/python3.10/shutil.py", line 254, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/to_html/output/md/figures/unnamed-chunk-1-1.png'

With a resulting file tree of

.
├── md
│   ├── bayes-play.md
│   ├── experiment-2-theory.md
│   ├── experiment-brainstorming.md
│   ├── figures
│   │   ├── unnamed-chunk-1-1.png
│   │   ├── unnamed-chunk-2-1.png
│   │   └── unnamed-chunk-3-1.png
│   ├── homepage.md
│   ├── index.md
│   ├── measurement.md
│   ├── .obsidian
│   └── stimuli.md
├── rmd
│   ├── bayes-play.Rmd
│   ├── experiment2-theory.Rmd
│   ├── .Rhistory
│   └── stan-file.stan
├── to_html
│   ├── compile.sh
│   ├── config.yaml
│   ├── links.txt
│   └── output
│       ├── html
│       │   ├── experiment-brainstorming.html
│       │   ├── figures
│       │   ├── index.html
│       │   ├── measurement.html
│       │   └── stimuli.html
│       └── md
│           ├── bayes-play.md
│           ├── experiment-2-theory.md
│           ├── experiment-brainstorming.md
│           ├── index.md
│           ├── measurement.md
│           └── stimuli.md
└── tree.txt

9 directories, 28 files

The conversion works when I go in and manually change image links to ![[image_name.png]].

Also, I noticed that using the md-only config that you suggested:

obsidian_entrypoint_path_str: '' # this line can be absent when using most recent master code, otherwise it is expected

md_folder_path_str:  '/home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/md/'
md_entrypoint_path_str: '/home/dave/Dropbox (Lehigh University)/post_doc/professional/projects/gaita/ideation/structured/md/homepage.md'

html_url_prefix: '/gaita/ideation/structured/html/'

toggles:
  compile_md: False
  process_all: True

doesn't correctly handle Obsidian-style wiki links. (And I had to manually drop that .obsidian directory in the 'vault' in order for the app to convert the correct directory). I'd have to look through the docs to see if there's a setting for preserving the links. But none of what I'm saying here relates to the current issue (ie, the latex) which indeed was resolved.

@dbraun31 dbraun31 closed this as completed Jan 3, 2023
@dwrolvink
Copy link
Collaborator

Yes md-->html expects proper markdown to be given as input, not obsidian markdown, which is why the whole note-->md step exists.

let's continue with your image tag problem in the other issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved
Projects
None yet
Development

No branches or pull requests

2 participants