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

Solution for formatting algorithms #103

Open
hturner opened this issue Sep 9, 2023 · 4 comments
Open

Solution for formatting algorithms #103

hturner opened this issue Sep 9, 2023 · 4 comments
Assignees

Comments

@hturner
Copy link

hturner commented Sep 9, 2023

I'm not aware of a tool to format algorithms in markdown, possibly something could be provided by rjtools as a consistent solution.

As an example, I tried to format the algorithm from here: https://tex.stackexchange.com/a/452565/21118.

---
title: "Formatting an algorithm"
output:
  html_document:
    highlight: tango
---

```{bash, attr.source='.numberLines', tidy = FALSE, eval = FALSE}
# Result: Write here the result
# Input: Write here the input
# Output: Write here the output
while while_condition do
  instructions
  if condition then
    instructions1
    instructions2
  else
    instructions3
  end
end
```
image

Apart from "do" and "end" not being highlighted it's not a bad solution. However it's not compatible with rjtools::rjournal_web_article:

image

What might be a better solution that could be recommended to authors?

@hturner
Copy link
Author

hturner commented Sep 9, 2023

LaTeX solutions for reference: https://www.overleaf.com/learn/latex/Algorithms. Some are more like code blocks and some are more like tables. I think a code-like version would be easier with R markdown, perhaps with a pseudocode language engine.

@dicook dicook self-assigned this Sep 27, 2023
@dicook dicook mentioned this issue Sep 28, 2023
1 task
@cderv
Copy link

cderv commented Sep 28, 2023

Quick demo of using pseudocode.js (https://saswat.padhi.me/pseudocode.js/) with R Markdown to mimic algorithm from LaTeX
https://rpubs.com/cderv/pseudocodejs

Maybe it could help.

Otherwise texPreview is always an option to have an image version of a LaTeX rendering part. They have a nice engine.
https://yonicd.github.io/texPreview/

Hope it helps

@hturner
Copy link
Author

hturner commented Sep 28, 2023

The pseudocode.js option looks like a good solution as returns proper HTML and MathJax. @ajgodfrey can you read the rendered algorithms in https://rpubs.com/cderv/pseudocodejs?

I guess the style could also be controlled via CSS to be more like the HTML tables.

@cderv
Copy link

cderv commented Sep 28, 2023

Main JS library (https://saswat.padhi.me/pseudocode.js/) offers solution for more recent MathJaX or even KaTeX. So if one of those solution is better, I believe it can also be used with R Markdown.

The example on rPubs is quite old - so it could also have been updated since then regarding accessibility. I see there is now support for MathJax 4 even: https://github.com/SaswatPadhi/pseudocode.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants