Git Product home page Git Product logo

mathjax-rails's Introduction

MathJax-Rails

We are living in an age where displaying math on web pages will never be hard - thanks to the great work of MathJax.

To quote the description from it's official website,

MathJax is an open source JavaScript display engine for mathematics that works in all modern browsers.

No more setup for readers. No more browser plugins. No more font installations… It just works.

Why bother with another gem?

Integrating MathJax into a rails project, however, could be a pain. MathJax is HUGE. It makes your project folder swollen, due to the excessive amount of files contained in this package. Including mathjax inside your developing directory makes your TextMate less responsive; when TextMate loses and then regains focus, it will scan the whole directory structure for changes.

Another problem is where to put it? public does not seem to be the best practice, since beginning with rails 3.1 public is by default ignored in production environment. Plus, it is big; when using git it leaves you no choice but to throw mathjax inside .gitignore, which makes sharing across developers less painless.

So?

This is when mathjax-rails comes into play!

  • It maintains MathJax as a system-wide directory.
  • By simply including mathjax-rails in your Gemfile, all your rails apps can benefit from MathJax immediately.
  • You can control the version of MathJax through the version of mathjax-rails, which is done simply via bundler.

Which version of MathJax does it use?

We maintain mathjax-rails to always use the latest version of stable MathJax releases.

To see the actual version, check the constant Mathjax::Rails::MATHJAXVERSION.

Usage

add this line to your Gemfile:

gem 'mathjax-rails'

then:

$ bundle install

The other gem

The new gem is more recently maintained.Thank you Manu S Ajith.

Gem Version

MathjaxRails

A Ruby gem for including mathjax for Rails 3.x or above apps

Installation

Add this line to your application's Gemfile:

gem 'mathjax-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mathjax-rails

Usage

add the following to config/routes.rb (you can change the name of course):

mathjax 'mathjax'

add the script tag inside app/views/layouts/application.html.erb:

<%= mathjax_tag %>

and you're done!

To try it, write a simple formula, for example:

\[\int_a^b f(x) dx=F(b)-F(a)\]

Configuration

By default, the TeX-AMS_HTML-full.js is loaded as the configuration file.

If you do not want any configuration file to be loaded:

<%= mathjax_tag :config=>false %>

If you want to load another configuration file, say Accessible-full.js:

<%= mathjax_tag :config=>'Accessible-full.js' %>

Additional configuration can be added directly before mathjax_tag, for example:

<script type="text/x-mathjax-config">
	MathJax.Hub.Config({
	 tex2jax: {
	   inlineMath: [ ['$','$'] ],
	   processEscapes: true
	 }
	});
</script>
<%= mathjax_tag %>

For more options please consult the MathJax documentation.

What did it do to my rails project?

Three simple things: it adds 1 controller MathjaxRailsController; 1 helper method mathjax_tag; 1 router method mathjax.

It won't pollute your rails project more than the above three.

Note

If you have a fast CDN service at hand, you don't need this gem.

Putting your MathJax at CDN is probably the best choice.

By dmarczal,

To work in rails 3.1 on production environment wih ngnix I just comment the follow line in production.rb

#config/environments/production.rb
#config.action_dispatch.x_sendfile_header = "X-Sendfile"

ChangeLog

  • 2013.11.21 Added support for Rails 4 apps.

  • 2011.7.28 Version 0.0.2 used to fail on Heroku. Now the problem is fixed. I used to use send_file without content_type, which causes a failure when deployed to Heroku. Now in version 0.0.3 I use render :type=>..., with the appropriate content-type set and the problem is solved.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

mathjax-rails's People

Contributors

anthonyjsmith avatar chbrown1293 avatar danielpuglisi avatar idabmat avatar manusajith avatar noprompt avatar oleander avatar pmq20 avatar yrral86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mathjax-rails's Issues

undefined method `mathjax_path' in a Rails engine

When I change the layout of an engine to the one of the application, I got the following error:

ActionView::Template::Error (undefined method `mathjax_path' for #<#<Class:0x007fd2bad1cbf0>:0x007fd2c1cca600>):
    12:       TeX: { equationNumbers: { autoNumber: "all" } }
    13:     });
    14:   </script>
    15:   <%= mathjax_tag %>
    16:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    17:   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    18:   <%= csrf_meta_tags %>
  app/views/layouts/application.html.erb:15:in `_app_views_layouts_application_html_erb___3320660116759457037_70271586191680'

and I try to find out mathjax_path, but only found it in mathjax-rails-2.5.1/lib/mathjax/rails/helpers.rb:

module Mathjax
  module Rails
    module ViewHelpers
      def mathjax_tag(opt={})
        opt[:config] ||= 'TeX-AMS_HTML-full.js'
        opt[:config] = nil if opt[:config] == false
        "<script src=\"#{mathjax_path(:uri=>'MathJax.js', config: opt[:config])}\" type=\"text/javascript\"></script>".html_safe
      end 
    end 
  end 
end
ActionView::Base.send :include, Mathjax::Rails::ViewHelpers

How to use

Hello I'm new in rails and i want to implement Tex math formulas in my application, so i find this gem, but i cant figure out how to use it!
Well, I followed the installation process and inserted the following code in a html.erb view home file:
<p>\[\int_a^b f(x) dx=F(b)-F(a)\]</p>
So when i run the server and no math function appeared in my page...
I think I'm missing out on something very obvious.Do I have to use <%= mathjax_tag %> to work with the Tex formulas?

extension mml3.js not working

An ActionView::MissingTemplate occurred in mathjax_rails#giveOutStaticFile:

Missing template mathjax/rails/mathjax_rails/giveOutStaticFile with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}.

Path traversal vulnerability without Session

Hi,

I've noticed that the function 'def giveOutStaticFile' does not properly sanitize the 'uri' variable:

filename = params[:uri]+ext
filepath = "../../../../vendor/#{Mathjax::Rails::DIRNAME}/#{filename}"

extname = File.extname(filename)[1..-1]
mime_type = Mime::Type.lookup_by_extension(extname)
options = Hash.new
options[:type] = mime_type.to_s unless mime_type.nil?
options[:disposition] = 'inline'
file = File.expand_path(filepath, __FILE__)

So it is possible to inject URLs like:
/mathjax/%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F../etc/passwd
or on heroku apps:
/mathjax/%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F../apps/Gemfile

Suggested fix (please check the PR: #25)
return render status: 404 if Pathname.new(filename).cleanpath.to_s != filename
Please consider that params[:uri] and params[:ext] could be subject to path traversal since both are included in the 'filename' variable.

If there is anything I can help you with, please feel free to ask.

Best regards,
Oliver Kuster

Change configuration - Is showing warning

Hello,

FIrst of all thanks for creating this gem, it's very usefull. I use it on an app but for some users Mathjax is showing a message on my website that goes to this page: http://www.mathjax.org/help/configuration/ . I think you should just change 2 lines of code. Sorry I tryied to do a pull request but I wasn't able to fix it due my beggining knowledge of javascript.

Thanks

Does this gem support server-side rendering?

There is a gap before MathJax comes into play. So user sees initial TeX string before MathJax starts to render TeX into something beautiful. For now I just hide elements with visibility: hidden that might contain TeX but this feels like a hack and not user-friendly.

Rails 3.1 in production

Hello,

There is some additional configuration to mathjax-rails to work on production with rails 3.1, because it's not work. It just work in development

Thanks

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.