From c67382d34070917b0e684aaa641699fa027ab7a2 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Thu, 4 Oct 2007 02:50:08 -0500 Subject: [PATCH 1/2] Start on LaTeX Pave the way for Jason's LaTeX macro support. Also, uniformize the capitalization of "ETag". --- vendor/plugins/action_cache/lib/action_cache.rb | 6 +++--- .../plugins/maruku/lib/maruku/ext/math/latex_fix.rb | 12 ++++++++++++ .../plugins/maruku/lib/maruku/ext/math/to_latex.rb | 11 ++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 vendor/plugins/maruku/lib/maruku/ext/math/latex_fix.rb diff --git a/vendor/plugins/action_cache/lib/action_cache.rb b/vendor/plugins/action_cache/lib/action_cache.rb index 16eace40..79544126 100644 --- a/vendor/plugins/action_cache/lib/action_cache.rb +++ b/vendor/plugins/action_cache/lib/action_cache.rb @@ -135,7 +135,7 @@ module ActionController controller.response.headers['Cache-Control'] == 'no-cache' controller.response.headers['Cache-Control'] = "max-age=#{controller.response.time_to_live}" end - controller.response.headers['Etag'] = %{"#{MD5.new(controller.response.body).to_s}"} + controller.response.headers['ETag'] = %{"#{MD5.new(controller.response.body).to_s}"} controller.response.headers['Last-Modified'] ||= Time.now.httpdate end @@ -148,13 +148,13 @@ module ActionController def send_not_modified(controller) controller.logger.info "Send Not Modified" - controller.response.headers['Etag'] = %{"#{MD5.new(fragment_body(controller)).to_s}"} + controller.response.headers['ETag'] = %{"#{MD5.new(fragment_body(controller)).to_s}"} controller.render(:text => "", :status => 304) end def client_has_latest?(cache_entry, controller) requestEtag = controller.request.env['HTTP_IF_NONE_MATCH'] rescue nil - responseEtag = cache_entry.headers['Etag'] rescue nil + responseEtag = cache_entry.headers['ETag'] rescue nil return true if (requestEtag and responseEtag and requestEtag == responseEtag) requestTime = Time.rfc2822(controller.request.env["HTTP_IF_MODIFIED_SINCE"]) rescue nil responseTime = Time.rfc2822(cache_entry.headers['Last-Modified']) rescue nil diff --git a/vendor/plugins/maruku/lib/maruku/ext/math/latex_fix.rb b/vendor/plugins/maruku/lib/maruku/ext/math/latex_fix.rb new file mode 100644 index 00000000..6ce588d6 --- /dev/null +++ b/vendor/plugins/maruku/lib/maruku/ext/math/latex_fix.rb @@ -0,0 +1,12 @@ +class String + + # fix some LaTeX command-name clashes + def fix_latex + if #{html_math_engine} == 'itex2mml' + s = self.gsub("\\mathop{", "\\operatorname{") + s.gsub("\\space{", "\\itexspace{") + else + self + end + end +end diff --git a/vendor/plugins/maruku/lib/maruku/ext/math/to_latex.rb b/vendor/plugins/maruku/lib/maruku/ext/math/to_latex.rb index 578eb713..fb925bc1 100644 --- a/vendor/plugins/maruku/lib/maruku/ext/math/to_latex.rb +++ b/vendor/plugins/maruku/lib/maruku/ext/math/to_latex.rb @@ -1,16 +1,17 @@ - module MaRuKu; module Out; module Latex +require 'maruku/ext/math/latex_fix' + def to_latex_inline_math - "$#{self.math.strip}$" + s = "$#{self.math.strip}$".fix_latex end def to_latex_equation if self.label l = "\\label{#{self.label}}" - "\\begin{equation}\n#{self.math.strip}\n#{l}\\end{equation}\n" + "\\begin{equation}\n#{self.math.strip}\n#{l}\\end{equation}\n".fix_latex else - "\\begin{displaymath}\n#{self.math.strip}\n\\end{displaymath}\n" + "\\begin{displaymath}\n#{self.math.strip}\n\\end{displaymath}\n".fix_latex end end @@ -18,4 +19,4 @@ module MaRuKu; module Out; module Latex "\\eqref{#{self.eqid}}" end -end end end \ No newline at end of file +end end end From 986c21527ad0c2ebbac8c71439b36172a48f26be Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Thu, 4 Oct 2007 03:16:45 -0500 Subject: [PATCH 2/2] First Batch of LaTeX Macros The first, uncontroversial, batch of LaTeX macros from Jason Blevins. --- app/views/wiki/tex.rhtml | 122 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 5 deletions(-) diff --git a/app/views/wiki/tex.rhtml b/app/views/wiki/tex.rhtml index 9edf7a7b..2e994700 100644 --- a/app/views/wiki/tex.rhtml +++ b/app/views/wiki/tex.rhtml @@ -9,19 +9,131 @@ \usepackage{hyperref} %----Macros---------- -\newcommand{\gt}{>} -\newcommand{\lt}{<} + +% Because of conflicts, \space and \mathop are converted to +% \itexspace and \operatorname during preprocessing. +% \over is simply unsupported. + +% \slash +\makeatletter +\newbox\slashbox \setbox\slashbox=\hbox{$/$} +\def\itex@pslash#1{\setbox\@tempboxa=\hbox{$#1$} + \@tempdima=0.5\wd\slashbox \advance\@tempdima 0.5\wd\@tempboxa + \copy\slashbox \kern-\@tempdima \box\@tempboxa} +\def\slash{\protect\itex@pslash} +\makeatother + +% Renames \sqrt as \oldsqrt and redefine root to result in \sqrt[#1]{#2} +\let\oldroot\root +\def\root#1#2{\oldroot #1 \of{#2}} + +% Manually declare the txfonts symbolsC font +\DeclareSymbolFont{symbolsC}{U}{txsyc}{m}{n} +\SetSymbolFont{symbolsC}{bold}{U}{txsyc}{bx}{n} +\DeclareFontSubstitution{U}{txsyc}{m}{n} + +% Declare specific arrows from txfonts without loading the full package +\makeatletter +\def\re@DeclareMathSymbol#1#2#3#4{% + \let#1=\undefined + \DeclareMathSymbol{#1}{#2}{#3}{#4}} +\re@DeclareMathSymbol{\neArrow}{\mathrel}{symbolsC}{116} +\re@DeclareMathSymbol{\neArr}{\mathrel}{symbolsC}{116} +\re@DeclareMathSymbol{\seArrow}{\mathrel}{symbolsC}{117} +\re@DeclareMathSymbol{\seArr}{\mathrel}{symbolsC}{117} +\re@DeclareMathSymbol{\nwArrow}{\mathrel}{symbolsC}{118} +\re@DeclareMathSymbol{\nwArr}{\mathrel}{symbolsC}{118} +\re@DeclareMathSymbol{\swArrow}{\mathrel}{symbolsC}{119} +\re@DeclareMathSymbol{\swArr}{\mathrel}{symbolsC}{119} +\makeatother + +% Widecheck +\makeatletter +\DeclareRobustCommand\widecheck[1]{{\mathpalette\@widecheck{#1}}} +\def\@widecheck#1#2{% + \setbox\z@\hbox{\m@th$#1#2$}% + \setbox\tw@\hbox{\m@th$#1% + \widehat{% + \vrule\@width\z@\@height\ht\z@ + \vrule\@height\z@\@width\wd\z@}$}% + \dp\tw@-\ht\z@ + \@tempdima\ht\z@ \advance\@tempdima2\ht\tw@ \divide\@tempdima\thr@@ + \setbox\tw@\hbox{% + \raise\@tempdima\hbox{\scalebox{1}[-1]{\lower\@tempdima\box +\tw@}}}% + {\ooalign{\box\tw@ \cr \box\z@}}} +\makeatother + +% udots (taken from yhmath) +\makeatletter +\def\udots{\mathinner{\mkern2mu\raise\p@\hbox{.} +\mkern2mu\raise4\p@\hbox{.}\mkern1mu +\raise7\p@\vbox{\kern7\p@\hbox{.}}\mkern1mu}} +\makeatother + +%% Renaming existing commands +\newcommand{\underoverset}[3]{\underset{#1}{\overset{#2}{#3}}} +\newcommand{\widevec}{\overrightarrow} \newcommand{\darr}{\downarrow} \newcommand{\nearr}{\nearrow} \newcommand{\nwarr}{\nwarrow} \newcommand{\searr}{\searrow} \newcommand{\swarr}{\swarrow} -\newcommand{\iff}{\Longleftrightarrow} -\newcommand{\impliedby}{\Leftarrow} +\newcommand{\curvearrowbotright}{\curvearrowright} +\newcommand{\uparr}{\uparrow} +\newcommand{\downuparrow}{\updownarrow} +\newcommand{\duparr}{\updownarrow} +\newcommand{\updarr}{\updownarrow} +\newcommand{\gt}{>} +\newcommand{\lt}{<} \newcommand{\map}{\mapsto} \newcommand{\embedsin}{\hookrightarrow} -\newcommand{\implies}{\Rightarrow} +\newcommand{\Alpha}{A} +\newcommand{\Beta}{B} +\newcommand{\Zeta}{Z} +\newcommand{\Eta}{H} +\newcommand{\Iota}{I} +\newcommand{\Kappa}{K} +\newcommand{\Mu}{M} +\newcommand{\Nu}{N} +\newcommand{\Rho}{P} +\newcommand{\Tau}{T} +\newcommand{\Upsi}{\Upsilon} +\newcommand{\omicron}{o} +\newcommand{\lang}{\langle} +\newcommand{\rang}{\rangle} +\newcommand{\Union}{\bigcup} +\newcommand{\Intersection}{\bigcap} +\newcommand{\Oplus}{\bigoplus} +\newcommand{\Otimes}{\bigotimes} +\newcommand{\Wedge}{\bigwedge} +\newcommand{\Vee}{\bigvee} +\newcommand{\coproduct}{\coprod} +\newcommand{\product}{\prod} +\newcommand{\closure}{\overline} +\newcommand{\integral}{\int} +\newcommand{\doubleintegral}{\iint} +\newcommand{\tripleintegral}{\iiint} +\newcommand{\quadrupleintegral}{\iiiint} +\newcommand{\conint}{\oint} +\newcommand{\contourintegral}{\oint} \newcommand{\qed}{\blacksquare} +\newcommand{\infinity}{\infty} +\renewcommand{\empty}{\emptyset} +\newcommand{\bottom}{\bot} +\newcommand{\minusb}{\boxminus} +\newcommand{\plusb}{\boxplus} +\newcommand{\timesb}{\boxtimes} +\newcommand{\intersection}{\cap} +\newcommand{\union}{\cup} +\newcommand{\Del}{\nabla} +\newcommand{\odash}{\circleddash} +\newcommand{\negspace}{\!} +\newcommand{\widebar}{\overline} +\newcommand{\textsize}{\normalsize} +\renewcommand{\scriptsize}{\scriptstyle} +\newcommand{\scriptscriptsize}{\scriptscriptstyle} +\newcommand{\mathfr}{\mathfrak} %-------------------------------------------------------------------