Skip to content
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

Fix inline math with code #57

Merged
merged 7 commits into from
Oct 18, 2021
Merged

Fix inline math with code #57

merged 7 commits into from
Oct 18, 2021

Conversation

zkamvar
Copy link
Member

@zkamvar zkamvar commented Oct 15, 2021

This updates the regex so that $, is no longer considered to be a starting element and adds an "ambiguous" flag that can be checked for the presence of a code block immediately preceding.

library(tinkr)
ex <- "some inline math, for example $R^2 = `r runif(1)`$, is _no longer_ failing with code"
f <- textConnection(ex)
y <- yarn$new(f)
close(f)
y$protect_math()$show()
#> some inline math, for example $R^2 = `r runif(1)`$, is *no longer* failing with code

Created on 2021-10-15 by the reprex package (v2.0.1)

this will fix #56

This will cause things like 10$? to break, but I think these kinds of
things are rare enough to allow for things like $\beta$, to be valid
@zkamvar zkamvar changed the title Mathematical Fix inline math with code Oct 15, 2021
@zkamvar zkamvar marked this pull request as draft October 15, 2021 18:31
@zkamvar
Copy link
Member Author

zkamvar commented Oct 15, 2021

Note, while this PR will fix #56, there is still the problem of math and links that begin a line:

library(tinkr)
ex <- "- so $\\beta^2 = `r runif(1)`$ works but,\n- $\\beta$ has the first dollar escaped"
f <- textConnection(ex)
y <- yarn$new(f)
close(f)
y$protect_math()$show()
#> - so $\beta^2 = `r runif(1)`$ works but,
#> - \$\beta$ has the first dollar escaped

Created on 2021-10-15 by the reprex package (v2.0.1)

@zkamvar zkamvar marked this pull request as ready for review October 15, 2021 23:15
Copy link
Member

@maelle maelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@@ -20,6 +20,8 @@
sink to the bottom of the document.
* 2021-09-14: numeric options fig.width and fig.height will no longer be quoted;
`transform_params()` is simplified and no longer requires glue.
* 2021-10-15: math with embedded code and punctuation following are now allowed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the edge cases 😁 👏

R/asis-nodes.R Outdated
# a space or another dollar.
start <- glue::glue("(?=^|{punks})[$]?[$][^{ace}$]")
# a space, a dollar sign, or any possible adjacent punctuation.
no_punks <- glue::glue("{minus_maybe}[^]}}>){ace},;.?$-])")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👩‍🎤

@zkamvar zkamvar merged commit 4333f08 into master Oct 18, 2021
@zkamvar zkamvar deleted the mathematical branch October 18, 2021 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline math with R code, commas returning errors
2 participants