From cc5b8cb3c09fd56834bc9ddcb823ce0be9c84b87 Mon Sep 17 00:00:00 2001 From: Philip McGrath Date: Mon, 25 Jul 2022 08:16:20 -0400 Subject: [PATCH] gnu: Add ruby-latex-decode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/packages/patches/ruby-latex-decode-fix-test.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. * gnu/packages/ruby.scm (ruby-latex-decode): New variable. Signed-off-by: Ludovic Courtès --- gnu/local.mk | 1 + .../patches/ruby-latex-decode-fix-test.patch | 66 +++++++++++++++++++ gnu/packages/ruby.scm | 52 +++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 gnu/packages/patches/ruby-latex-decode-fix-test.patch diff --git a/gnu/local.mk b/gnu/local.mk index cbfe880d6e..ca3b83c550 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1782,6 +1782,7 @@ dist_patch_DATA = \ %D%/packages/patches/rocm-comgr-3.1.0-dependencies.patch \ %D%/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch \ %D%/packages/patches/rocm-opencl-runtime-4.3-noopencl.patch \ + %D%/packages/patches/ruby-latex-decode-fix-test.patch \ %D%/packages/patches/ruby-mustache-1.1.1-fix-race-condition-tests.patch \ %D%/packages/patches/ruby-sanitize-system-libxml.patch \ %D%/packages/patches/rustc-1.39.0-src.patch \ diff --git a/gnu/packages/patches/ruby-latex-decode-fix-test.patch b/gnu/packages/patches/ruby-latex-decode-fix-test.patch new file mode 100644 index 0000000000..58d7d16258 --- /dev/null +++ b/gnu/packages/patches/ruby-latex-decode-fix-test.patch @@ -0,0 +1,66 @@ +From 698e39a251d433e2cd2934586a2dfc5e6582c4f9 Mon Sep 17 00:00:00 2001 +From: Philip McGrath +Date: Sun, 24 Jul 2022 09:12:55 -0400 +Subject: [PATCH] Improve readability of whitespace tests + +This change fixes the test for `~x` in some environments in which it +was previously failing. + +Related to https://github.com/inukshuk/latex-decode/issues/13 +--- + features/step_definitions/latex.rb | 5 +++++ + features/symbols.feature | 7 ------- + features/whitespace.feature | 13 +++++++++++++ + 3 files changed, 18 insertions(+), 7 deletions(-) + create mode 100644 features/whitespace.feature + +diff --git a/features/step_definitions/latex.rb b/features/step_definitions/latex.rb +index 4b1b595..fca63c0 100644 +--- a/features/step_definitions/latex.rb ++++ b/features/step_definitions/latex.rb +@@ -5,3 +5,8 @@ end + Then /^the result should be ('|")(.*)\1$/ do |quote,value| + expect(@result).to eq(value) + end ++ ++# For whitespace or other characters that are hard to read in source code: ++Then /^I should get '([^']*)' \+ U\+(\h{4,}) \+ '([^']*)'$/ do |pre,code,post| ++ expect(@result).to eq(pre + code.hex.chr(Encoding::UTF_8) + post) ++end +diff --git a/features/symbols.feature b/features/symbols.feature +index 46d9a51..f8a5e84 100644 +--- a/features/symbols.feature ++++ b/features/symbols.feature +@@ -12,10 +12,3 @@ Feature: Decode LaTeX symbol directives + | \\uparrow | ↑ | + | \\downarrow | ↓ | + | \\rightarrow | → | +- +- Scenarios: Whitespace +- | latex | unicode | description | +- | x\\,x | x x | small space | +- | x~x | x x | non-breaking space | +- | ~x |  x | non-breaking space | +- +diff --git a/features/whitespace.feature b/features/whitespace.feature +new file mode 100644 +index 0000000..fe5b208 +--- /dev/null ++++ b/features/whitespace.feature +@@ -0,0 +1,13 @@ ++Feature: Decode LaTeX whitespace directives ++ As a hacker who works with LaTeX ++ I want to be able to decode LaTeX whitespace ++ ++ Scenario Outline: LaTeX to Unicode transformation ++ When I decode the string '' ++ Then I should get
 + U+ + 
++
++  Scenarios: Whitespace
++    | latex | pre | code | post | description                |
++    | x~x   | 'x' | 00A0 | 'x'  | non-breaking space         |
++    | ~y    | ''  | 00A0 | 'y'  | leading non-breaking space |
++    | z\\,z | 'z' | 2009 | 'z'  | small space                |
+-- 
+2.32.0
+
diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 746bb9b6ce..5111b9ae2b 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13111,3 +13111,55 @@ adaptation of TeX math syntax for web display.  Ritex makes inserting math
 into HTML pages easy.  It supports most TeX math syntax as well as macros.")
     ;; doesn't clearly state -only vs -or-later
     (license license:gpl2)))
+
+(define-public ruby-latex-decode
+  (package
+    (name "ruby-latex-decode")
+    (version "0.4.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/inukshuk/latex-decode")
+                    (commit (string-append "v" version))))
+              (sha256
+               (base32
+                "1f5j67ayd04pjkmzvn0hk7cr8yqvn0gyg9ns6a0vhzj2gwna9ihy"))
+              (file-name (git-file-name name version))))
+    (build-system ruby-build-system)
+    (native-inputs
+     (list ruby-cucumber
+           ruby-ritex
+           ruby-rspec))
+    (arguments
+     (list
+      #:test-target "cucumber"
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'extract-gemspec 'avoid-bundler
+            (lambda args
+              (substitute* "Rakefile"
+                (("require 'bundler" orig)
+                 (string-append "# " orig " # patched for Guix"))
+                (("Cucumber::Rake::Task\\.new[(]:cucumber[)]" orig)
+                 (string-append orig " do |c|\n"
+                                "  c.bundler = false # patched for Guix\n"
+                                "end"))
+                (("Bundler\\.setup" orig)
+                 (string-append "true # " orig " # patched for Guix")))
+              (substitute* "cucumber.yml"
+                ;; thanks to avoiding bundler, we can't use this option
+                ((" --publish-quiet")
+                 ""))))
+          (add-after 'replace-git-ls-files 'replace-another-git-ls-files
+            (lambda args
+              (substitute* "latex-decode.gemspec"
+                (("`git ls-files -- [{]test,spec,features[}]/\\*`")
+                 "`find {test,spec,features} -type f | sort`")))))))
+    (home-page "https://github.com/inukshuk/latex-decode")
+    (synopsis "Convert LaTeX to Unicode")
+    (description
+     "This package provides a gem to convert LaTeX input to Unicode.  Its
+original use was as an input filter for BibTeX-Ruby, but it can be used
+independently to decode LaTeX.  Many of the patterns used by this Ruby gem are
+based on François Charette's equivalent Perl module @code{LaTeX::Decode}.")
+    (license license:gpl3+)))