Forum: support


RE: Using code blocks with line breaks as answers in Answer list [ Reply ] By: Achim Zeileis on 2025-06-10 03:05 | [forum:50089] |
Thanks for drilling down to this yourself and posting your solution on StackOverflow as well. I have responded there: https://stackoverflow.com/questions/79659588/ |
RE: Using code blocks with line breaks as answers in Answer list [ Reply ] By: Caio Hamamura on 2025-06-10 00:43 | [forum:50088] |
I found the problem. The issue when it is processing the question within [`read_exercise()`](https://r-forge.r-project.org/scm/viewvc.php/pkg/exams/R/read_exercise.R?root=exams#l44). When we they try to [## make sure we get items on multiple lines right](https://r-forge.r-project.org/scm/viewvc.php/pkg/exams/R/read_metainfo.R?root=exams#l150) there is this line: ``` x <- paste(x, collapse = " ") ``` Which collapses the vector in a single line, completely removing the information of line breaks, if you change it to: ``` x <- paste(x, collapse = "\n") ``` Then it will work fine. I don't know if this will mess with other formats though. But in my end I installed this tweaked version. |
Using code blocks with line breaks as answers in Answer list [ Reply ] By: Caio Hamamura on 2025-06-09 22:40 | [forum:50087] |
I tried to create a simple question using `code blocks` with `verbatim` environment and compile that to pdf. But the problem is that the line breaks are ignored and the output code block becomes single line. ```latex \begin{question} How can I retrieve only the `id` and `name` columns from the `user` table in a SQL database? \begin{answerlist} \item \begin{verbatim} SELECT id, name FROM user; \end{verbatim} \item \begin{verbatim} SELECT * FROM user; \end{verbatim} \end{answerlist} \end{question} ``` I assume the \begin{answerlist} has some preprocessing which trims away the line breaks, is there any way to display code blocks as alternatives for `schoice` questions? I also tried to use markdown "``` " but that doesn't work either. Inspecting the intermediate exercise1.tex from `texdir` I can see the linebreaks are trimmed away: ```latex %%%%%%%%%%%%%%%%%% %% exercise1.tex %%%%%%%%%%%%%%%%%% \begin{question} How can I retrieve only the `id` and `name` columns from the `user` table in a SQL database? \begin{answerlist} \item \begin{verbatim} SELECT id, name FROM user; \end{verbatim} \item \begin{verbatim} SELECT * FROM user; \end{verbatim} \end{answerlist} \end{question} ``` |