Skip to content

Commit

Permalink
Merge pull request #59 from stefano-meschiari/v0.9.7
Browse files Browse the repository at this point in the history
Fix bug where numbers starting with 0 would not render correctly
  • Loading branch information
stefano-meschiari authored Jan 1, 2023
2 parents f4e06a6 + f56fa56 commit 0efe78e
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 31 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master, 0.9.0]
branches: [main, master]
pull_request:
branches: [main, master]

Expand All @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -29,18 +29,21 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v1
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
33 changes: 22 additions & 11 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:
Expand All @@ -12,24 +14,33 @@ name: pkgdown
jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: pkgdown
extra-packages: any::pkgdown, local::.
needs: website

- name: Deploy package
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.9.4
Date: 2022-03-02 22:54:43 UTC
SHA: a69df1f48fe2a9f4af34a2398e5aeb503ba8d4b0
Version: 0.9.6
Date: 2022-11-28 01:32:37 UTC
SHA: b0733d28ed4550137676a24c9473955b829dbde5
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: latex2exp
Type: Package
Title: Use LaTeX Expressions in Plots
Version: 0.9.6
Date: 2022-11-27
Version: 0.9.7
Date: 2022-12-28
Authors@R: person("Stefano", "Meschiari", email="[email protected]", role=c("aut", "cre"))
Description: Parses and converts LaTeX math formulas to R's plotmath
expressions, used to enter mathematical formulas and symbols to be rendered as
Expand All @@ -28,5 +28,5 @@ Suggests:
rlang,
dplyr
VignetteBuilder: knitr
RoxygenNote: 7.1.2
RoxygenNote: 7.2.2
Language: en-US
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ importFrom(magrittr,"%>%")
importFrom(stringr,fixed)
importFrom(stringr,str_c)
importFrom(stringr,str_detect)
importFrom(stringr,str_length)
importFrom(stringr,str_match)
importFrom(stringr,str_match_all)
importFrom(stringr,str_replace)
Expand Down
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# 0.9.7 (12/28/2022)
## Bug fixes
* In math mode, numbers that started with 0 would be displayed without it (e.g.
$\beta_{02}$ would render as $\beta_{2}$) (fixes #58)

## New features
The following symbols were added:

* `\S` ('§')
* `\permil` ('‰')
* `\blacksquare` ('■')
* `\square` ('□')
* `\smwhtsquare` ('▫')
* `\smblksquare` ('▪')
* `\smallint` ('∫')
* `\ell` ('ℓ')
* `\house` ('⌂')
* `\dots` ('…')

The following commands were added:
* `\pmod{x}` renders as `(mod x)`

# 0.9.6 (11/27/2022)
## Bug fixes
* Fixes swapped wedge and vee symbols (#55, credit to @ebolove)
Expand Down
1 change: 1 addition & 0 deletions R/latex2exp.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @importFrom stringr str_match
#' @importFrom stringr str_match_all
#' @importFrom stringr fixed
#' @importFrom stringr str_length
NULL

#' Deprecated; use \code{\link{TeX}} instead.
Expand Down
3 changes: 3 additions & 0 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ render_latex <- function(tokens, user_defined=list(), hack_parentheses=FALSE) {
} else {
tok$rendered <- split[1,2]
}
if (str_starts(tok$rendered, "0") && str_length(tok$rendered) > 1) {
tok$rendered <- str_c("0*", str_sub(tok$rendered, 2))
}
}

tok$left_operator <- str_detect(tok$rendered, fixed("$LEFT"))
Expand Down
20 changes: 16 additions & 4 deletions R/symbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ latex_supported = list(
"\\times" = "$LEFT %*% $RIGHT",
"\\circ" = "$LEFT ~ '\u25e6' ~ $RIGHT",
"\\ast" = "$LEFT ~ symbol('\\053') ~ $RIGHT",
"\\%" = "$LEFT ~ symbol('\\045') ~ $RIGHT",
"\\perp" = "$LEFT ~ symbol('\\136') ~ $RIGHT",
"\\bullet" = "$LEFT ~ symbol('\\267') ~ $RIGHT",
"\\otimes" = "$LEFT ~ symbol('\\304') ~ $RIGHT",
Expand All @@ -105,7 +104,8 @@ latex_supported = list(
"\\wedge" = "$LEFT ~ symbol('\\331') ~ $RIGHT",
"\\angle" = "$LEFT ~ symbol('\\320') ~ $RIGHT",
"\\cdots" = "$LEFT ~ cdots ~ $RIGHT",
"\\ldots" = "$LEFT ~ ldots ~ $RIGHT"
"\\ldots" = "$LEFT ~ ldots ~ $RIGHT",
"\\mod" = "$LEFT ~ 'mod' ~ $RIGHT"
),

"set operators" = list(
Expand All @@ -127,7 +127,8 @@ latex_supported = list(
"\\wp" = "symbol('\\303')",
"\\surd" = "symbol('\\326')",
"\\neg" = "symbol('\\330')",
"\\ni" = "symbol('\\047')"
"\\ni" = "symbol('\\047')",
"\\pmod" = "$LEFT ~ group('(', 'mod' ~ $arg1, ')')"
),

# Square root, sum, prod, integral, etc.
Expand Down Expand Up @@ -224,7 +225,18 @@ latex_supported = list(
"\\degree" = "'\\u0b0'",
"\\prime" = "$LEFT * minute ",
"\\second" = "$LEFT * second ",
"\\third" = "$LEFT * '\\u2034'"
"\\third" = "$LEFT * '\\u2034'",
"\\%" = "symbol('\\045')",
"\\S" = "'\u00a7'",
"\\permil" = "'\u2030'",
"\\blacksquare" = "'\u25a0'",
"\\square" = "'\u25a1'",
"\\smwhtsquare" = "'\u25ab'",
"\\smblksquare" = "'\u25aa'",
"\\smallint" = "'\u222b'",
"\\ell" = "'\u2113'",
"\\house" = "'\u2302'",
"\\dots" = "'\u2026'"
),

# Decorations
Expand Down
3 changes: 2 additions & 1 deletion README.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ knitr::opts_chunk$set(fig.width=7, fig.height=5, fig.path = "man/figures/README-
```
<!-- badges: start -->
[![R-CMD-check](https://github.com/stefano-meschiari/latex2exp/workflows/R-CMD-check/badge.svg)](https://github.com/stefano-meschiari/latex2exp/actions)
[![R-CMD-check](https://github.com/stefano-meschiari/latex2exp/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/stefano-meschiari/latex2exp/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

# latex2exp <img src="man/figures/logo.png" align="right">
Expand All @@ -35,4 +36,4 @@ devtools::install_github('stefano-meschiari/latex2exp')
```

## Supported LaTeX commands
[Table of supported LaTeX](https://www.stefanom.io/latex2exp/articles/supported-commands.html)
[Table of supported LaTeX](https://www.stefanom.io/latex2exp/articles/supported-commands.html)
7 changes: 7 additions & 0 deletions tests/testthat/test_simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ test_that("Mix of numbers and letters renders correctly", {
expect_renders_same(TeX("$2\\alpha$"), 2*alpha)
})

test_that("Numbers render correctly", {
expect_renders_same(TeX("$0$"), 0)
expect_renders_same(TeX("$01$"), 0*1)
expect_renders_same(TeX("$\\beta_{02}$"), beta[0*2])

})

test_that("User-defined latex renders correctly", {
expect_renders_same(TeX("$\\mycommand$", user_defined = list(
"\\mycommand" = "alpha"
Expand Down

0 comments on commit 0efe78e

Please sign in to comment.