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
Can pandoc deal with ifdefined or skip certain parts with special LaTeX macros. #6096
Comments
|
Pandoc's LaTeX reader currently doesn't support One option is to simply include some code that redefines the environment in question to be a no-op. E.g. create a and then run Pandoc will parse the newenvironment and apply it when it comes to CCSXML, skipping the whole thing. |
|
Pandoc also doesn't seem to be able to deal with What I get as output is It seems that the only way to cope with this would be to define two environments (one for true, one for false) and shim each? |
|
The other issue is that it's very hard to write a 'no-op' environment. I want to print nothing in one case. One way of doing that is the |
|
@nathanieltagg We ought to add support for
|
|
The which treats that environment as a comment. Supporting that switch would have also done the job, although that's rather specific. When I first posted this, I assumed that pandoc was a cut-down latex compiler, not a ground-up parser. |
That does not eliminate the contents of the environment. E.g. if I want to ignore all |
|
Note that |
|
Just experiencing similar problems with \newif within Rmarkdown, where the following fails to compile to pdf with a pandoc error, it used to work before the latest update, any ideas? |
|
@annlia - important to know what pandoc version you're using, what output you get, and what you expect. |
|
Here is the full version of the .Rmd file I am using With pandoc 2.13 it compiles fine, with later versions it doesn't. The correct output is attached. Just added further details including a workaround to use a previous version of pandoc here https://community.rstudio.com/t/r-markdown-with-newif-fails-to-compile-to-pdf-after-update/125603/2 |
|
This contains things that are meant to be processed by RMarkdown, so it won't work with pandoc by itself. I suspect that your issue is with something in RMarkdown, so maybe you should check with someone who is knowledgeable about that. |
|
That is correct, it is an Rmarkdown file, and indeed I am processing it through rmarkdown (in RStudio) and not with pandoc by itself. In fact, I do not know where the communication between the two fails, but by (only) replacing the current version of pandoc with version 2.13 the file compiles correctly. Specifically, within RMarkdown it is sufficient to use
So perhaps something has changed in the way they interact in the latest versions... |
|
The example above shows that the I'm not sure why this would ever have worked, but it's probably due to a bug in a previous version! The |
|
If that is the case, I am grateful for the bug, since it is the only thing that allows me to compile my files... As you can see from above I tried to post on other forums where hopefully RMarkdown experts could chime in, but unfortunately, I did not receive a response. Thanks again for taking an interest in this issue. |
|
I can reproduce the issue when converting the RMarkdown-generated intermediary Markdown: \newif\ifsol
\soltrue
\ifsol
Text to conditionally skip
\fiJust for completeness, here's the output from the current version and pandoc 2.13 for Current version [ RawBlock
(Format "tex") "\\newif\\ifsol\n\\def\\iffalse\\iftrue"
, RawBlock (Format "tex") "\\iftrue"
, Para
[ Str "Text"
, Space
, Str "to"
, Space
, Str "conditionally"
, Space
, Str "skip"
]
, RawBlock (Format "tex") "\\fi"
]pandoc 2.13[ RawBlock (Format "tex") "\\newif\\ifsol\n\\soltrue"
, RawBlock (Format "tex") "\\ifsol"
, Para
[ Str "Text"
, Space
, Str "to"
, Space
, Str "conditionally"
, Space
, Str "skip"
]
, RawBlock (Format "tex") "\\fi"
] |
|
@annlia you can work around this by using raw blocks: I haven't tried it, but I believe this should also work when including |
|
I was testing with rmarkdown should certainly use the raw attribute syntax when doing this, to avoid funny results. But, why do we get bad results without it? Do you understand that, @tarleb? The native output is almost the same. |
|
This is a FWIW comment on the underlying logic of rmarkdown code chunks and inline code in relation to tex macros. @annlia was trying to preserve an existing workflow when I originally saw this issue on community.rstudio.com. As I could find no way to do that under the current pandoc version, I worked through several ways that it might be done alternatively in an rmarkdown file. So, this is for those more interested in the general question of conditionally sending values of There are two ways of returning objects to stdout: in a chunk and inline. In the motivating example, a logical object "solution" was defined as TRUE in a chunk and was then to be used as an argument: The inline A error arises, however if the will fail silently, sending nothing to stdout or stderr. That seems unhelpful, though, considering that one does not generally want to be referring to non-existing objects. To do so should be an error and should fail noisily. The exercise leads me to wonder if macros are fitted for use as variables, rather than constants. The purpose of rendering a document that contains executed code is so that the text in stdout faithfully reflects the return value of the object in question within the |
RMarkdown does an R preprocessing step and then passes the resulting Markdown to pandoc. However, there is a new project, @quarto-dev, which does use filters. I don't fully understand what's going on, but it appears that something werid happens during macro expansion: somehow Another alternative to the raw attribute syntax mentioned above is hence to disable LaTeX macro extension ( |
|
First note: this bug only occurs with Second note: from the source of T.P.Readers.LaTeX.Macros, we see -- \newif\iffoo' defines:
-- \iffoo to be \iffalse
-- \footrue to be a command that defines \iffoo to be \iftrue
-- \foofalse to be a command that defines \iffoo to be \iffalseSo this is probably why we are getting \def\ifsol\iffalse
\def\soltrue{\def\ifsol\iftrue}
\def\solfalse{\def\ifsol\iffalse}Then when it gets to This extra expansion doesn't occur with |
|
|
|
I tried removing the retokenize step altogether in which looks good. |
This was causing serious problems with `newif` commands. See #6096. And it didn't seem to make any difference for the tests; I assume that, unless there's some untested behavior, this is something that has now become unnecessary.
|
While this is better, it still causes a LaTeX error because of the Ideally we'd just parse the raw tex as without resolving |
pandoc has difficulties to parse certain commands, for example from the ACM template like
\begin{CCSXML}. In general, I would like to have the opportunity to not compile certain parts of the document. Therefore I was using\ifdefined\somecommand \standardTex \else \pandocTex \fi. Is there another build-in feature to achieve that I could not find in the documentation, or is it bug in pandoc that it tries to interpret content within not applicable branches of if statements.Might be related to #3689
The text was updated successfully, but these errors were encountered: