How to generate images? - manpage

Generates an HTML page with a link to image without image file:
man -Hfirefox 3 exit
Generates an HTML page with link and file, but it is empty (zero size).
Also generates the code for the table, but it is empty:
zcat /usr/share/man/man3/exit.3.gz | groff -mandoc -Thtml > exit.3.html
Generates an html page with table, but the characters are misinterpreted.
In addition, some attributes (bold or underlined) are lost to certain words:
man -P cat 3 exit | man2html > exit.3.html
What is considered as an image is in fact a table (man 3 exit):
┌──────────┬───────────────┬─────────────────────┐
│Interface │ Attribute │ Value │
├──────────┼───────────────┼─────────────────────┤
│exit() │ Thread safety │ MT-Unsafe race:exit │
└──────────┴───────────────┴─────────────────────┘
netpbm-10.69.02-1 package is installed.
How to generate the images (or table in text mode) with the second method?
EDIT:
It is also necessary to install the psutils package. In this case, the PNG is created.
The content of the table is then visible but with no bordure.
And there has undesirable characters.

Related

Project structure to graphical layout (VSCode)?

Is there an extension or something that could help me to visually represent the project tree structure of a large project folders (components)? For example if I have react/apps/components/... to export it to a structure graphical view something like this, directly from VSCode:
UPDATE: I have found a way to export project tree structure in textual format like shown below using project-tree VSCode extension, but it's still not what I was looking for. Maybe something to export this format to graphical?
├─ apps
│ ├─ one
│ │ ├─ a
│ │ ├─ b
│ │ ├─ c
Looking at the text representation you can export from VSCode, I think it would be easy to write a script that turns that text representation into a Mermaid graph.
Mermaid is a markdown-like language that allows you to create graphics using text.
The example that you provided could be translated into Mermaid's syntax:
graph LR
Apps --> One
One --> A
One --> B
One --> C
graph LR states that this is a graph that will be plotted from left to right.
Each A --> B line establishes a relationship between two elements that will be drawn.
I don't have enough reputation to post the resulting image, but you can open this site and paste the code to see it: https://mermaid.live/

Different copies of question with table for Moodle with R-Exams

I would like to generate several copies of a question with randomly generated data in order to upload to Moodle and make a quiz. This question would include a table which depends on the data generated each time. How can this be done? I tried using xtable but it generates a table with no margins and format when uploaded to Moodle. I also tried ggpubr but it was not possible to include the table.
I read that one can generate a '.png', for example, and using 'include_supplement' and \includegraphics for .Rnw the file is imported into the file. This is useful when only one copy is generated because only one file would be the one imported. But what happens when multiple copies of the question with different data have to be created at once?
Any help would be appreciated.
Thank you.
Overview
Table formatting is not so straightforward for Moodle, both when starting from an exercise in R/LaTeX format (Rnw, as you do) or in R/Markdown format (Rmd). Below I'm showing a couple of variations of what you can do although I'm not 100% happy with all of them. In all cases the example is static but could be made dynamic in the "usual" way by inserting the random numbers into the respective tables. If you have problems with making one of the solutions dynamic, please let me know.
Plain
When you are starting in Rnw you typically generate a {tabular} object either by hand or via packages like xtable or knitr::kable etc. These are converted to valid HTML and imported into Moodle but the formatting with lines (horizontal and/or vertical) is not preserved. The same is true when starting in Rmd and using plain Markdown markup to code the table (again by hand or via knitr::kable etc.).
Example:
Rnw:
\begin{question}
Consider the following table:
\begin{tabular}{lrr}
\hline
Name & Min & Max \\
\hline
Foo & 0 & 1 \\
Bar & 0 & 100 \\
\hline
\end{tabular}
What is the overall maximum?
\end{question}
\exname{Table}
\extype{num}
\exsolution{100}
\extol{0.01}
Rmd: Would be similar to above but the table in plain Markdown as:
| Name | Min | Max |
|:-----|----:|----:|
| Foo | 0 | 1 |
| Bar | 0 | 100 |
Some other learning management systems (like OpenOLAT for example) offer suitable table classes in their CSS so that we can tweak the <table> in the resulting HTML to <table class="mytable"> (where the "mytable" class would need to be provided in the CSS). I looked around a bit in Moodle's question editor but there doesn't seem to be support for such dedicated CSS table styles. If anyone knows more about this I would appreciate some pointers.
HTML
The best alternative to this is probably to start in Rmd but instead of writing the table in Markdown you can use full HTML directly. This gives you extensive possibilities for styling the cells by hand. There are also various packages that help you with this. Below I'm using a combination of knitr::kable and kableExtra::kable_styling. The latter offers many more options than those that I use below.
Example:
Rmd:
Question
========
Consider the following table:
```{r, echo = FALSE, results = "asis"}
d <- data.frame(
Name = c("Foo", "Bar"),
Min = c(0, 1),
Max = c(0, 100)
)
kableExtra::kable_styling(
knitr::kable(d, format = "html", booktabs = TRUE),
bootstrap_options = "bordered", full_width = FALSE, position = "left")
```
What is the overall maximum?
Meta-information
================
exname: Table
extype: num
exsolution: 100
extol: 0.01
Rnw: I guess the same trick should be possible in Rnw exercises, i.e., include HTML in the LaTeX exercise and preserve that when converting to HTML with pandoc. However, I didn't manage to find the right flag for that. So this currently works just from Rmd exercises.
LaTeX
You can also typeset the table with LaTeX and use pdfLaTeX for rendering and then convert the output to PNG or SVG. This is supported by the tex2image() function in the exams package. This can be used in both Rnw and Rmd exercises and the resulting image has to be included in the exercise. The disadvantage is that the fonts etc. differ between the table and the main question (and you have to play with the fontsize and resolution in tex2image()). Moreover, this is relatively slow because pdfLaTeX has to be run on each exercise with such a table.
Example:
Rnw:
\begin{question}
Consider the following table:
<<echo=FALSE, results=hide>>=
tab <- '\\begin{tabular}{lrr}
\\hline
Name & Min & Max \\\\
\\hline
Foo & 0 & 1 \\\\
Bar & 0 & 100 \\\\
\\hline
\\end{tabular}'
tex2image(tab, name = "tab", dir = ".", pt = 8, resize = 250)
#
\includegraphics{tab.png}
What is the overall maximum?
\end{question}
\exname{Table}
\extype{num}
\exsolution{100}
\extol{0.01}
Rmd: The same code chunk generating the image could be used in Rmd. Just the \includegraphics would need to be replace by the corresponding ![]() Markdown.
CSS
Yet another option to render the table in Moodle is to insert a custom stylesheet with a class for the <table class="..."> to be rendered. A worked example is provided by Kenji Sato in his blog at: https://www.kenjisato.jp/en/post/2020/07/moodle-bordered-table/. We plan to integrate this with a couple of typical classes in exams2moodle() so that the CSS does not have to be inserted in every exercise manually. However, we did not yet get round to impelement this.
Sometimes we use quick and dirty hack.
$$
\begin{matrix}
\text{Name} & \text{Min} & \text{Max} \\
\ldots
\end{matrix}
$$
This hack has at least two advantages :)
It can be applied in a big team where everyone knows latex but only some guys know markdown.
It works both from .Rmd and .Rnw files. The plain \begin{tabular} way works only from .Rnw files.
Obvious con:
It's dirty!

A table in .md document included from external file

Is there an elegant way how to include table from an external file in markdown document rendered by GitHub?
Non elegant solutions I can think of:
include it as image (this one is really really ugly)
use Rmarkdown and print table using R (wont be rendered by default)
Just to give a bit of explanation. I am using a set of README.md files in my git repository (hosted by GitHub), so it is really clear to browse repo online, because GitHub renders automatically README.md file in every subdirectory.
I am algorithmically generating summary tables that should be included in those documents. It would be way more elegant if that table could be read from external file, because I do not want to write scripts that will modify README.md files directly.
There is no way to include files within markdown. So you need a "preprocessing" stage to generate the markdown which is then shown on Github (or rendered with normal markdown tools).
What Github supports is a basic table layout, which you'd need to render:
Solution 1: scripting
You could add something like this to your README.md:
<!-- TABLE_GENERATE_START -->
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
<!-- TABLE_GENERATE_END -->
And then have a script which pulls in the external table, reformats it to match the github format and puts it between the two comment.
Solution 2: pandoc
Pandoc is a document converter framework with many possible inputs and outputs. If you're up to learn another tool you could
reformat you table into a markdown file using csv2table into table.md
create a readme_header.md and readme_footer.md with the markdown before/after the table
merge the three files with cat readme_header.md table.md readme_footer.md > REAME.md
Of course you can also do a mixture of both solutions, e.g. generate table.md using a script and merge using cat

emacs ff-find-other-file does not find my header

Somehow I can't make emacs' ff-find-other-file to get my header file. Here is what I have (minimal example):
cd ~/tmp
mkdir test
cd test
mkdir -p src/a/b inc/a/b
echo "aaaa" > src/a/b/a.cpp
echo "bbbb" > inc/a/b/a.hpp
tree
gives:
.
├── inc
│   └── a
│   └── b
│   └── a.hpp
└── src
└── a
└── b
└── a.cpp
This is similar to my project structure.
emacs -Q src/a/b/a.cpp
Then copying this in *scratch* and executing it with C-x C-e:
(setq cc-search-directories '("." "../inc" "../inc/*" "../../inc/*" "../../../inc/*" "/usr/include"))
and running ff-find-other-file in buffer a.cpp, only results in a prompt in the minibuffer:
Find or create a.hpp in: ~/tmp/test/src/a/b/
C-h v on ff-search-directories returns cc-search-directories, and on cc-search-directories I get the list above.
I expect ff-find-other-file to look in ../../../inc/*, and find a.hpp. Why doesn't it?
Edit: it seems to be the recursive part that doesn't work here.
After:
cp inc/a/b/a.hpp inc/
a.hpp is found from a.cpp.
The help about ff-search-directories says:
The stars are not wildcards: they are searched for together with
the preceding slash. The star represents all the subdirectories except
`..', and each of these subdirectories will be searched in turn.
Note that this quote if from the help for ff-search-directories, while the list I modified is cc-search-directories. I can't see why that would make a difference though.
This and other threads on SO made me believe * would recursively search the directory tree. Wrong?
* represents every immediate sub-directory of its parent; nothing more.
The commentary has it worded slightly more clearly:
The star is not a general wildcard character: it just indicates that the subdirectories of this directory must each be searched in turn.
i.e. For this specific example I would expect "../../../inc/*/b" to work. Or indeed "../../../inc/*/*" (as you've ended up using).
See also https://stackoverflow.com/a/23662870/324105 and note in particular that you can define functions to dynamically generate the target file path(s).
I suspect you want the a/b to be determined based on the original path, so a function to return the appropriate path to the other file would be your best solution here.
Another options is to use Projectile and execute the projectile-find-other-file command. Since projectile knows about your project structure, it will match your cpp/h files automatically. It is a little slower than ff-find-other-file, but it seems to do the job pretty well.
Oh, the search turns out not to be recursive after all. These other questions and answers here made me misread the help (quoted in the question).
"Each of these subdirectories will be searched in turn", does not imply that their subdirectories also will be searched.
Since the depth of my tree is limited, I just modified my cc-search-directories:
(setq cc-search-directories '("."
"../inc" "../inc/*" "../../inc/*" "../../../inc/*"
"../../inc/*/*" "../../../inc/*/*/*"
"../src" "../src/*" "../../src/*" "../../../src/*"
"../../src/*/*" "../../../src/*/*/*"
"/usr/include" "/usr/local/include/*"))

Difference between Github and npm markdown

I have an Node package up on Github (https://github.com/jrootham/argument-spec) and npm (https://www.npmjs.com/package/argument-spec). There is a specification table where the first cell contains the word 'undefined'. It shows up fine on Github but is blank on npm. Anybody have any idea what is going on. I searched for docs on npm markdown but none appeared.
If npm readme html pages are generated (as in this question) with evilstreak/markdown-js, then you have some table examples, like this one:
| First Header | Second Header |
| ------------- | ------------- |
| Content 1 | Content 2 |
| Content 3 | Content 4 |
There is issue 230 discussing about the proper supoprt for table with this package, but it should be able to render most tables correctly.
In your case, see if adding delimiters change anything:
####Specification meanings
|Specification|Valid argument|
-----------|----------
|undefined|anything|
|''|string|
The PR (Pull Request 480 mentions:
This updates newww to use marky-markdown to process readme content. Highlights include:
Human-readable code!
Lots of tests
Explicit HTML content policy with sanitize-html
Server-side syntax highlighting
Gravatar URL cleanup
GitHub relative link cleanup
Better tagging of badge elements
Forward-looking CDN image support
That project in turn uses markdown-it, which has a few issues around table.
#Jim Rootham is right about the process npm uses to display markdown: they are filtered through marky-markdown and then displayed. It looks like you've found a bug somewhere in this process; you should open an issue on the npm website repository, https://github.com/npm/newww