0

I want add a code-chunk with pseudocode in my bookdown project, but i dont found a proper way to do this.

An this old issue on github/bookdown they talk about this feature, but I found nothing newer.

In this tex.stackexchange post they generate pseudocode via latex which is ignored in Rmd files.

```{}
**INPUT:** input;  
**OUTPUT:** result;  

**IF** this_is_True:  
  do_this;  
**ELSE**
  select B from input;  
  do something whith input;  
  **FOR EACH** $a_i$ **in** B   
    do something with $a_i$;
```

The code shows an example chunk which i want to have transformed in this: simple expected result.

Currently it ignors markdown and the $ symboles to make mathematical expression (letter 'a' with a small index i).

Best regards
ralph

update 29.04
- example code block from Rmd-file and add a simple expected output

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
ralph
  • 73
  • 8
  • I don't get the issue. Can you not just enclose the pseudocode the same way you would any other code block, like you've done in the markdown in this question? – camille Apr 26 '19 at 16:07
  • @camille thx for the response. I updeted my post and add the result which i want to have – ralph Apr 29 '19 at 12:24
  • Still unclear. Having it printed as a mathematical expression, i.e. subscript *i*, is what you want but can't get, or what you're getting but don't want? It also seems like the ability to put text in bold, etc will depend on the syntax highlighting style you use – camille Apr 29 '19 at 14:39
  • yes, I want the mathematical expression and the highlighting, but it ignores ** and $ inside the code chunk. It prints the code as it is. – ralph Apr 30 '19 at 14:00
  • The linked answer on tex.stackexchange works fine for PDF output. Which output format are you interested in? – Ralf Stubner Apr 30 '19 at 15:48
  • @RalfStubner thank you for your answer!! At first we want a HTML output but maybe later we want also provide a pdf version. – ralph May 02 '19 at 06:29
  • I tested your procedure myself a while ago. Unfortunately I miss the highlighting of the pseudo code. That means the style of bold words is the same as the normal text and the grey area around the code is missing. – ralph May 02 '19 at 08:53
  • Are you referring to my answer provided below? As shown in the screen shots, the bold text is formatted correctly. – Ralf Stubner May 02 '19 at 12:47

1 Answers1

1

How about line blocks:

---
output:
  pdf_document: default
  html_document: default
---

| **INPUT:** input;  
| **OUTPUT:** result;  
| 
| **IF** this_is_True:  
|   do_this;  
| **ELSE**
|   select B from input;  
|   do something whith input;  
|   **FOR EACH** $a_i$ **in** B   
|     do something with $a_i$;

HTML output:

enter image description here

PDF Output:

enter image description here

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75