From c45a89a5c686a064db1bbc9b22a5c1d13098e272 Mon Sep 17 00:00:00 2001 From: satikaj <117552851+satikaj@users.noreply.github.com> Date: Sun, 3 Dec 2023 01:38:15 +1100 Subject: [PATCH 1/5] test: extend ipynb pdf test to verify inline latex math display --- Gemfile | 2 ++ test/models/task_test.rb | 10 ++++++++++ test_files/submissions/vectorial_graph.ipynb | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/Gemfile b/Gemfile index 29c23de09..d62bfe7a0 100644 --- a/Gemfile +++ b/Gemfile @@ -89,3 +89,5 @@ gem 'icalendar' gem 'rest-client' gem 'net-smtp', require: false + +gem 'pdf-reader' diff --git a/test/models/task_test.rb b/test/models/task_test.rb index a95d07e58..2f36c385f 100644 --- a/test/models/task_test.rb +++ b/test/models/task_test.rb @@ -357,9 +357,19 @@ def test_ipynb_to_pdf assert File.exist? path assert File.exist? task.final_pdf_path + # Check inline latex math display + pdf_content = read_pdf_content(task.final_pdf_path) + assert_includes pdf_content, "bmi = weigh2\n height" + td.destroy assert_not File.exist? path unit.destroy! end + def read_pdf_content(pdf_path) + require 'pdf-reader' + pdf_reader = PDF::Reader.new(pdf_path) + pdf_reader.pages.map(&:text).join("\n") + end + end diff --git a/test_files/submissions/vectorial_graph.ipynb b/test_files/submissions/vectorial_graph.ipynb index 3176f1dab..1575481cb 100644 --- a/test_files/submissions/vectorial_graph.ipynb +++ b/test_files/submissions/vectorial_graph.ipynb @@ -937,6 +937,20 @@ "source": [ "Testing a raw cell with $10 invalid latex code" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Testing inline latex math display" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Formula for calculating BMI: $\\text{bmi}=\\frac{\\text{weight}}{\\text{height}^2}$" + ] } ], "metadata": { From 014604dc8bfefa4a678b057ac299b49114d0375f Mon Sep 17 00:00:00 2001 From: satikaj <117552851+satikaj@users.noreply.github.com> Date: Sun, 3 Dec 2023 01:39:39 +1100 Subject: [PATCH 2/5] fix: support inline latex math display in ipynb pdfs --- app/views/layouts/application.pdf.erbtex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/application.pdf.erbtex b/app/views/layouts/application.pdf.erbtex index 1eafb3d38..150c455f0 100644 --- a/app/views/layouts/application.pdf.erbtex +++ b/app/views/layouts/application.pdf.erbtex @@ -13,7 +13,7 @@ \input|"python3 jupynotex.py #2 #1" } -\usepackage[fencedCode,hashEnumerators]{markdown} +\usepackage[fencedCode,hashEnumerators,pipeTables,texMathDollars]{markdown} \usepackage{luatextra} \defaultfontfeatures{Ligatures=TeX} From 4f5399611da1950b749e3f3e88e7f209ada5143c Mon Sep 17 00:00:00 2001 From: satikaj <117552851+satikaj@users.noreply.github.com> Date: Tue, 5 Dec 2023 20:49:05 +1100 Subject: [PATCH 3/5] refactor: move pdf-reader into the proper gem group --- Gemfile | 3 +-- Gemfile.lock | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index d62bfe7a0..6c5dbbb41 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,7 @@ group :development, :test, :staging do gem 'minitest' gem 'minitest-around' gem 'webmock' + gem 'pdf-reader' end # Database @@ -89,5 +90,3 @@ gem 'icalendar' gem 'rest-client' gem 'net-smtp', require: false - -gem 'pdf-reader' diff --git a/Gemfile.lock b/Gemfile.lock index 048a2cbef..fb099587d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: https://rubygems.org/ specs: + Ascii85 (1.1.0) actioncable (7.0.4.3) actionpack (= 7.0.4.3) activesupport (= 7.0.4.3) @@ -69,6 +70,7 @@ GEM addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) aes_key_wrap (1.1.0) + afm (0.2.2) amq-protocol (2.3.2) ast (2.4.2) backport (1.2.0) @@ -170,6 +172,7 @@ GEM grape-swagger-rails (0.3.1) railties (>= 3.2.12) hashdiff (1.0.1) + hashery (2.1.2) hirb (0.7.3) http-accept (1.7.0) http-cookie (1.0.5) @@ -242,6 +245,12 @@ GEM parallel (1.22.1) parser (3.2.1.1) ast (~> 2.4.1) + pdf-reader (2.11.0) + Ascii85 (~> 1.0) + afm (~> 0.2.1) + hashery (~> 2.0) + ruby-rc4 + ttfunk pkg-config (1.5.1) public_suffix (5.0.1) puma (6.1.1) @@ -340,6 +349,7 @@ GEM ruby-filemagic (0.7.3) ruby-ole (1.2.12.2) ruby-progressbar (1.13.0) + ruby-rc4 (0.1.5) ruby-saml (1.13.0) nokogiri (>= 1.10.5) rexml @@ -384,6 +394,7 @@ GEM thor (1.2.1) tilt (2.1.0) timeout (0.3.2) + ttfunk (1.7.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unf (0.1.4) @@ -436,6 +447,7 @@ DEPENDENCIES moss_ruby (>= 1.1.4) mysql2 net-smtp + pdf-reader puma rack-cors rails (~> 7.0) From 7575d643b30d14b08623f60679ef537a37094675 Mon Sep 17 00:00:00 2001 From: satikaj <117552851+satikaj@users.noreply.github.com> Date: Tue, 5 Dec 2023 20:53:23 +1100 Subject: [PATCH 4/5] refactor: fix alphabetical order of gems --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 6c5dbbb41..b42e34365 100644 --- a/Gemfile +++ b/Gemfile @@ -34,8 +34,8 @@ group :development, :test, :staging do gem 'faker' gem 'minitest' gem 'minitest-around' - gem 'webmock' gem 'pdf-reader' + gem 'webmock' end # Database From 09992515676640b0b9e06c4416ee0997fa40edf0 Mon Sep 17 00:00:00 2001 From: satikaj <117552851+satikaj@users.noreply.github.com> Date: Sun, 28 Apr 2024 21:36:23 +1000 Subject: [PATCH 5/5] refactor: simplify latex math unit test assert --- test/models/task_test.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/test/models/task_test.rb b/test/models/task_test.rb index 2f36c385f..b2042d096 100644 --- a/test/models/task_test.rb +++ b/test/models/task_test.rb @@ -1,4 +1,5 @@ require 'test_helper' +require 'pdf-reader' # # Contains tests for Task model objects - not accessed via API @@ -357,19 +358,11 @@ def test_ipynb_to_pdf assert File.exist? path assert File.exist? task.final_pdf_path - # Check inline latex math display - pdf_content = read_pdf_content(task.final_pdf_path) - assert_includes pdf_content, "bmi = weigh2\n height" + reader = PDF::Reader.new(task.final_pdf_path) + assert reader.pages[3].text.include? "bmi = weigh2\n height" td.destroy assert_not File.exist? path unit.destroy! end - - def read_pdf_content(pdf_path) - require 'pdf-reader' - pdf_reader = PDF::Reader.new(pdf_path) - pdf_reader.pages.map(&:text).join("\n") - end - end