This is a small sample article to demonstrate usage of texor to convert code environments.
Pandoc naturally converts verbatim environment easily, however the redefination of other commands such as example, example*, Sinput etc to verbatim does not work well in pandoc.
Hence, the texor package uses a stream editor to search find and replace matching code environments to verbatim before pandoc touches it.
This way the the code is not lost in conversion, also a pandoc extension
is used to add attributes to the markdown code using
fenced_code_attributes
Code Environment types are well summarized in the table 1
| Code Environment Type | |||||
|---|---|---|---|---|---|
| Example | example | example* | |||
| S.series | Sin | Sout | Sinput | Soutput | Scode |
| Special Verbatim | boxedverbatim |
While verbatim is naturally supported in pandoc,other extensions of verbatim environment like boxedverbatim from moreverb package (Fairbairns, A. Duggan, R. Schöpf and V. Eijkhout 2011) falls back to normal verbatim.
1. verbatim :
print("Hello world")2. boxedverbatim :
print("Hello world")S series code environement is defined in Rjournal.sty file. Most of these are extensions of verbatim environment and retain the original formatting of the content in HTML.
1. Sinput :
print("Hello world")2. Soutput :
[1] "hello world"3. Sin :
print("Hello world")4. Sout :
[1] "hello world"Example series of code environment is defined in Rjournal.sty file. Examples are extensions of verbatim environment and retain the original formatting of the content in HTML.
1. example :
print("Hello world")2. example* :
print("Hello world")A small example of this is visble in 1. This is a common practice in Rnews articles as it used to add a boxed border around the code which looks attractive. However, in web articles there isn’t much advantage to it.
code_in_figure <- function() {
if (pandoc_version >= 3) {
print("Code in Figure Supported")
}
else {
print("code in Figure not supported")
}
}
Pandoc v3 or greater (Krewinkel and A. Lucero 2023) has a Figure object which allows non-image figures to be treated like one. This is why texor package requires atleast version 3 of pandoc.
We can use code environments in a table using minipage environments. This is not a common practice among LaTeX article authors, but a few articles had such complex structures. So, as a example to demonstrate pandoc and texor package’s capabilities, I have included a few of them.
Table 2 is an example of code environments within a table.
| Language | Function Defination Syntax |
|---|---|
| R | |
| Python | |
| Lua | |
A similar arrangement can be had for figures/plots besides code environment. Table 3 demonstrates a table with code and figure.
| Code | Plot |
|---|---|
|
Using inline code in LaTeX is possible using \verb command. It would
be repoduced similarly, as a Inline code element.
\verb|x <- 1:100|will be represented as x <- 1:100 in Inline format.
Code chunks within an Schunk environment to demonstrate Input/Output
Input :
print("Hello world")Output :
[1] "hello world"Similar arrangement can be had for Plots as well using figure environnment.
Input :
x <- 1:100
y <- dbinom(x,100,prob = 0.5)
plot(x,y)Output :
Including R code chunks in an article that is to be converted to R markdown can be a bit tricky as the knitr package will interpret and execute the R code chunks as actual code bits. A workaround for this issue has been described in this posit support article. Below is an example with the workaround adapted from (Nathan Stephens 2022).
```{r}
plot(cars)
```In summary the texor package supports:
Almost all code environments in RJournal.
Code Highlight for R language.
Inline Code.
Code in different environments like tables/figures.
This article is converted from a Legacy LaTeX article using the texor package. The pdf version is the official version. To report a problem with the html, refer to CONTRIBUTE on the R Journal homepage.
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Ulayil, "Working with Code environments in texor", The R Journal, 2025
BibTeX citation
@article{RJ-2025-000,
author = {Ulayil, Abhishek},
title = {Working with Code environments in texor},
journal = {The R Journal},
year = {2025},
note = {https://rjournal.github.io/},
volume = {17},
issue = {3},
issn = {2073-4859},
pages = {1}
}