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 latex math display in pdfs generated from ipynb #432

Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ group :development, :test, :staging do
gem 'faker'
gem 'minitest'
gem 'minitest-around'
gem 'pdf-reader'
gem 'webmock'
end

Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -436,6 +447,7 @@ DEPENDENCIES
moss_ruby (>= 1.1.4)
mysql2
net-smtp
pdf-reader
puma
rack-cors
rails (~> 7.0)
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.pdf.erbtex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
10 changes: 10 additions & 0 deletions test/models/task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions test_files/submissions/vectorial_graph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down