Skip to content

Commit

Permalink
Added custom settings for macro and MathJax configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
macdems committed Sep 14, 2015
1 parent 7ae1cc3 commit 9e2d4a8
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 28 deletions.
30 changes: 30 additions & 0 deletions app/views/redmine_latex_mathjax/_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<fieldset>

<legend><%= l(:redmine_latex_mathjax_config_title) %></legend>

<p><label><%= l(:redmine_latex_mathjax_label_url) %>:</label>
<%= text_field_tag 'settings[latex_mathjax_url]', @settings['latex_mathjax_url'] %><br />
</p>

<p><label><%= l(:redmine_latex_mathjax_label_inline_delimiter_start) %>:</label>
<%= text_field_tag 'settings[latex_mathjax_inline_delimiter_start]', @settings['latex_mathjax_inline_delimiter_start'] %><br />
</p>

<p><label><%= l(:redmine_latex_mathjax_label_inline_delimiter_end) %>:</label>
<%= text_field_tag 'settings[latex_mathjax_inline_delimiter_end]', @settings['latex_mathjax_inline_delimiter_end'] %><br />
</p>

<p><label><%= l(:redmine_latex_mathjax_label_block_delimiter_start) %>:</label>
<%= text_field_tag 'settings[latex_mathjax_block_delimiter_start]', @settings['latex_mathjax_block_delimiter_start'] %><br />
</p>

<p><label><%= l(:redmine_latex_mathjax_label_block_delimiter_end) %>:</label>
<%= text_field_tag 'settings[latex_mathjax_block_delimiter_end]', @settings['latex_mathjax_block_delimiter_end'] %><br />
</p>


<p><label><%= l(:redmine_latex_mathjax_label_html_css_config) %>:</label>
<%= text_area_tag 'settings[latex_mathjax_html_css_config]', @settings['latex_mathjax_html_css_config'] %><br />
</p>

</fieldset>
Empty file.
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# English strings go here for Rails i18n
en:
redmine_latex_mathjax_config_title: "Redmine LaTeX MathJax Configuration"
redmine_latex_mathjax_label_url: "MathJax URL:"
redmine_latex_mathjax_label_inline_delimiter_start: "Inline LaTeX opening delimiter:"
redmine_latex_mathjax_label_inline_delimiter_end: "Inline LaTeX closing delimiter:"
redmine_latex_mathjax_label_block_delimiter_start: "Block LaTeX opening delimiter:"
redmine_latex_mathjax_label_block_delimiter_end: "Block LaTeX closing delimiter:"
redmine_latex_mathjax_label_html_css_config: "MathJax HTML-CSS configuration:"
# my_label: "My label"
54 changes: 34 additions & 20 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
author_url 'https://github.com/vDorst'
version '0.3.0'

settings :default => {
'latex_mathjax_url' => 'https://cdn.mathjax.org/mathjax/latest/MathJax.js',
'latex_mathjax_inline_delimiter_start' => '$',
'latex_mathjax_inline_delimiter_end' => '$',
'latex_mathjax_block_delimiter_start' => '$$',
'latex_mathjax_block_delimiter_end' => '$$',
'latex_mathjax_html_css_config' => "availableFonts: ['TeX']\n"
}, :partial => 'redmine_latex_mathjax/settings'

Redmine::WikiFormatting::Macros.register do
desc "MathJax Macro:\n\n" +
"Usage:\n"+
Expand All @@ -22,14 +31,11 @@
end

class MathJaxEmbedMacro
# Modify the delimiters.
@@inline_delimiter = '$'
@@display_delimiter = '$$'
# Modify URL to MathJax.
@@url = 'https://cdn.mathjax.org/mathjax/latest/MathJax.js'

def self.mj_error(text)
return "<span id=\"errorExplanation\"><strong>MathJaxMacro:</strong> #{text}</span>".html_safe
end

def self.mj_macro(obj, arg, text)
## Check any argument is given
if ((text == nil) && (arg.length == 0))
Expand All @@ -41,25 +47,33 @@ def self.mj_macro(obj, arg, text)
end
# Use text is arg == nil
if (text != nil)
arg = text
return "#{MathJaxEmbedMacro.delimiterStartBlock} #{text} #{MathJaxEmbedMacro.delimiterEndBlock}".html_safe
else
# Check argument length in Argument Mode
if (arg != nil) && (arg.length < 1)
return self.mj_error("Input must be at least 1 character long.")
end
return "#{MathJaxEmbedMacro.delimiterStartInline} #{arg} #{MathJaxEmbedMacro.delimiterEndInline}".html_safe
end
# Check argument length in Argument Mode
if (arg != nil) && (arg.length < 1)
return self.mj_error("Input must be atlease 1 characet long.")
end
# Check for illegal charaters.
if arg =~ /[<>]/
return self.mj_error("Illegal characters found! Don\'t using < or >")
end
return "#@@delimiter #{arg} #@@delimiter".html_safe
end
def self.inline_delimiter()
return @@inline_delimiter

def self.delimiterStartInline()
return Setting.plugin_redmine_latex_mathjax_macro['latex_mathjax_inline_delimiter_start'] || ""
end

def self.delimiterEndInline()
return Setting.plugin_redmine_latex_mathjax_macro['latex_mathjax_inline_delimiter_end'] || ""
end

def self.delimiterStartBlock()
return Setting.plugin_redmine_latex_mathjax_macro['latex_mathjax_block_delimiter_start'] || ""
end
def self.display_delimiter()
return @@display_delimiter

def self.delimiterEndBlock()
return Setting.plugin_redmine_latex_mathjax_macro['latex_mathjax_block_delimiter_start'] || ""
end

def self.URLToMathJax()
return @@url
return Setting.plugin_redmine_latex_mathjax_macro['latex_mathjax_url'] || ""
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ module Hooks
class ViewLayoutsBaseHtmlHeadHook < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context={})
return "<script type=\"text/x-mathjax-config\">
MathJax.Hub.Config({
MathJax.Hub.Config({
extensions: ['tex2jax.js'],
jax: ['input/TeX', 'output/HTML-CSS'],
tex2jax: {
inlineMath: [ ['" + MathJaxEmbedMacro.inline_delimiter.html_safe + "','" + MathJaxEmbedMacro.inline_delimiter.html_safe + "'] ],
displayMath: [ ['" + MathJaxEmbedMacro.display_delimiter.html_safe + "','" + MathJaxEmbedMacro.display_delimiter.html_safe + "'] ],
inlineMath: [ ['" + MathJaxEmbedMacro.delimiterStartInline.html_safe + "','" + MathJaxEmbedMacro.delimiterEndInline.html_safe + "'] ],
displayMath: [ ['" + MathJaxEmbedMacro.delimiterStartBlock.html_safe + "','" + MathJaxEmbedMacro.delimiterEndBlock.html_safe + "'] ],
processEscapes: false,
ignoreClass: 'text-diff'
},
'HTML-CSS': { availableFonts: ['TeX'] }
'HTML-CSS': {
" + Setting.plugin_redmine_latex_mathjax_macro['latex_mathjax_html_css_config'] + "
}
});
MathJax.Hub.Typeset();
</script>" +
javascript_include_tag(MathJaxEmbedMacro.URLToMathJax + '?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=onload') +
"<script type=\"text/javascript\">
MathJax.Hub.Typeset();
</script>\n" +
javascript_include_tag(MathJaxEmbedMacro.URLToMathJax + '?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=onload') + "
<script type=\"text/javascript\">
// Own submitPreview script with Mathjax trigger. Copy & Paste of public/javascripts/application.js
function MJsubmitPreview(url, form, target) {
$.ajax({
Expand Down

0 comments on commit 9e2d4a8

Please sign in to comment.