var EXPORTED_SYMBOLS = ["extLoader"];
/*
*
* It is assumed that preamble has these definitions:
* \renewcommand{\div}[1]{\nabla\cdot #1} % for divergence
* \newcommand{\curl}[1]{\nabla\times #1} % for curl
* \newcommand{\parenthesis}[1]{\left(#1\right)} % (...)
* \newcommand{\bracket}[1]{\left[#1\right]} % [...]
*
*/
var extLoader = {
pointers: null,
collapsed: false,
info: {
GUID: "98190d5a-af88-461b-97bd-16d80310fa90",
name: "Latex tools",
version: "0.2",
developer: "Thomas",
description: "Convert QFN's symbols to Latex, and ...",
qfnVersion: ["2.4C", "*"],
ffVersion: ["3.*", "*"]
},
xul: "\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
",
initialize: function () {},
toggle: function(b) {
var document = this.pointers.document;
document.getElementById('thom-but0').collapsed = b;
document.getElementById('thom-but1').collapsed = b;
document.getElementById('thom-but2').collapsed = b;
document.getElementById('thom-but3').collapsed = b;
document.getElementById('thom-but4').collapsed = b;
},
insertImage: function() {
var textbox = this.pointers.QFN.getEditor();
this.pointers.api.insertTextAtCursorPoint(
"\n\\begin{figure}[!htp]\n\t" +
"\\centering\n\t" +
"\\includegraphics[width=0.7\\textwidth]{imageFile}\n\t" +
"\\caption[Image short caption]{Image long caption}\n\t" +
"\\label{fig:img1}\n" +
"\\end{figure}\n"
);
},
insert: function(pre, post) {
var textbox = this.pointers.QFN.getEditor();
var selStart = textbox.selectionStart;
var selEnd = textbox.selectionEnd;
//
if (textbox.value.substr(selEnd-1, 1) == " ") {
selEnd -= 1;
textbox.selectionEnd = selEnd;
}
//
this.pointers.api.insertTextAtCursorPoint(pre + textbox.value.substring(selStart, selEnd) + post);
if (selStart == selEnd) {
textbox.selectionStart -= 1;
textbox.selectionEnd -= 1;
}
},
insertBracket: function () {
this.insert("{", "}")
},
insertEmphasis: function () {
this.insert("\\emph{", "}");
},
insertBold: function () {
this.insert("\\textbf{", "}");
},
insertUnderline: function () {
this.insert("\\underline{", "}");
},
insertFootnote: function () {
this.insert("\\footnote{", "}");
},
insertSection: function () {
this.insert("\\section{", "}");
},
insertSubsection: function () {
this.insert("\\subsection{", "}");
},
insertSubsubsection: function () {
this.insert("\\subsubsection{", "}");
},
insertLabel: function () {
this.insert("\\label{", "}");
},
insertRef: function () {
this.insert("\\ref{", "}");
},
bareConvert: function() {
this.solve("", "");
},
inlineConvert: function() {
this.solve("$", "$");
},
fullConvert: function() {
this.solve("\n\\begin{eqnarray}\n\t", "\n\\end{eqnarray}\n", true); //also align them all
},
solve: function(prefix, suffix, aligned) {
var textbox = this.pointers.QFN.getEditor();
var selStart = textbox.selectionStart;
var selEnd = textbox.selectionEnd;
//
if (textbox.value.substr(selEnd-1, 1) == " ") {
selEnd -= 1;
textbox.selectionEnd = selEnd;
}
//
var txt = (selStart == selEnd) ? textbox.value : textbox.value.substring(selStart, selEnd);
var converted = this.convertMath(txt);
if (aligned && txt.split("\n").length > 1) //only align when there is more than one equation
converted = converted.replace(/(\n\s*)/g, "\\\\$1\t&&").replace(/^(\s*)/g, "$1&&");
//
if (selStart == selEnd)
textbox.value = prefix + converted + suffix;
else
this.pointers.api.insertTextAtCursorPoint(prefix + converted + suffix);
//Make sure QFN saves changes
textbox.setAttribute("saveMe", true)
},
convertMath: function (txt) {
return txt.
replace(/\u2207\u00D7/g, "\\curl{}"). //Define curl
replace(/\u2207\./g, "\\div{}"). //Define div
replace(/sqrt/g, "\\sqrt{}").
replace(/k0/g, "k_0"). //k0
replace(/n0/g, "n_0"). //n0
replace(/n1/g, "n_1"). //n1
replace(/n2/g, "n_2"). //n2
replace(/n3/g, "n_3"). //n3
replace(/n4/g, "n_4"). //n4
replace(/Ex\(/g, "E_x("). //Ex(
replace(/Ex\=/g, "E_x="). //Ex=
replace(/Ex\ /g, "E_x "). //'Ex '
replace(/Ex\ \=/g, "E_x ="). //Ex =
replace(/Ey\(/g, "E_y("). //Ey(
replace(/Ey\=/g, "E_y="). //Ey=
replace(/Ey\ /g, "E_y "). //'Ey '
replace(/Ey\ \=/g, "E_y ="). //Ey =
replace(/Ez\(/g, "E_z("). //Ez(
replace(/Ez\=/g, "E_z="). //Ez=
replace(/Ez\ /g, "E_z "). //'Ez '
replace(/Ez\ \=/g, "E_z ="). //Ez =
replace(/Hx\(/g, "H_x("). //Hx(
replace(/Hx\=/g, "H_x="). //Hx=
replace(/Hx\ /g, "H_x "). //'Hx '
replace(/Hx\ \=/g, "H_x ="). //Hx =
replace(/Hy\(/g, "H_y("). //Hy(
replace(/Hy\=/g, "H_y="). //Hy=
replace(/Hy\ /g, "H_y "). //'Hy '
replace(/Hy\ \=/g, "H_y ="). //Hy =
replace(/Hz\(/g, "H_z("). //Hz(
replace(/Hz\=/g, "H_z="). //Hz=
replace(/Hz\ /g, "H_z "). //'Hz '
replace(/Hz\ \=/g, "H_z ="). //Hz =
replace(/sin\(/g, "\\sin("). //sin(
replace(/sin\ \(/g, "\\sin ("). //sin (
replace(/cos\(/g, "\\cos("). //cos(
replace(/cos\ \(/g, "\\cos ("). //cos (
replace(/tan\(/g, "\\tan("). //tan(
replace(/tan\ \(/g, "\\tan ("). //tan (
replace(/csc\(/g, "\\csc("). //csc(
replace(/csc\ \(/g, "\\csc ("). //csc (
replace(/acos\(/g, "\\arccos("). //acos(
replace(/acos\ \(/g, "\\arccos ("). //acos (
replace(/arccos\(/g, "\\arccos("). //arccos(
replace(/arccos\ \(/g, "\\arccos ("). //arccos (
replace(/atan\(/g, "\\arctan("). //atan(
replace(/atan\ \(/g, "\\arctan ("). //atan (
replace(/arctan\(/g, "\\arctan("). //arctan(
replace(/arctan\ \(/g, "\\arctan ("). //arctan (
replace(/log\(/g, "\\log("). //log(
replace(/log\ \(/g, "\\log ("). //log (
replace(/exp\(/g, "\\exp("). //exp(
replace(/exp\ \(/g, "\\exp ("). //exp (
replace(/cot\(/g, "\\cot("). //cot(
replace(/cot\ \(/g, "\\cot ("). //cot (
replace(/max\(/g, "\\max("). //max(
replace(/max\ \(/g, "\\max ("). //max (
replace(/min\(/g, "\\min("). //min(
replace(/min\ \(/g, "\\min ("). //min (
replace(/sup\(/g, "\\sup("). //sup(
replace(/sup\ \(/g, "\\sup ("). //sup (
replace(/lim\(/g, "\\lim("). //lim(
replace(/lim\ \(/g, "\\lim ("). //lim (
replace(/(.*)(\(([^\)]*)\))(.*)/g, "$1\\parenthesis{$3}$4"). //Replace (....) with \parenthesis{....}; Level 1
replace(/(.*)(\(([^\)]*)\))(.*)/g, "$1\\parenthesis{$3}$4"). //Replace (....) with \parenthesis{....}; Level 2
replace(/(.*)(\(([^\)]*)\))(.*)/g, "$1\\parenthesis{$3}$4"). //Replace (....) with \parenthesis{....}; Level 3
replace(/(.*)(\(([^\)]*)\))(.*)/g, "$1\\parenthesis{$3}$4"). //Replace (....) with \parenthesis{....}; Level 4
replace(/(.*)(\(([^\)]*)\))(.*)/g, "$1\\parenthesis{$3}$4"). //Replace (....) with \parenthesis{....}; Level 5
replace(/(.*)(\(([^\)]*)\))(.*)/g, "$1\\parenthesis{$3}$4"). //Replace (....) with \parenthesis{....}; Level 6
replace(/(.*)(\(([^\)]*)\))(.*)/g, "$1\\parenthesis{$3}$4"). //Replace (....) with \parenthesis{....}; Level 7
replace(/(.*)(\(([^\)]*)\))(.*)/g, "$1\\parenthesis{$3}$4"). //Replace (....) with \parenthesis{....}; Level 8
replace(/(.*)(\[([^\]]*)\])(.*)/g, "$1\\bracket{$3}$4"). //Replace [....] with \bracket{....}; Level 1
replace(/(.*)(\[([^\]]*)\])(.*)/g, "$1\\bracket{$3}$4"). //Replace [....] with \bracket{....}; Level 2
replace(/(.*)(\[([^\]]*)\])(.*)/g, "$1\\bracket{$3}$4"). //Replace [....] with \bracket{....}; Level 3
replace(/(.*)(\[([^\]]*)\])(.*)/g, "$1\\bracket{$3}$4"). //Replace [....] with \bracket{....}; Level 4
replace(/(.*)(\[([^\]]*)\])(.*)/g, "$1\\bracket{$3}$4"). //Replace [....] with \bracket{....}; Level 5
replace(/(.*)(\[([^\]]*)\])(.*)/g, "$1\\bracket{$3}$4"). //Replace [....] with \bracket{....}; Level 6
replace(/(.*)(\[([^\]]*)\])(.*)/g, "$1\\bracket{$3}$4"). //Replace [....] with \bracket{....}; Level 7
replace(/(.*)(\[([^\]]*)\])(.*)/g, "$1\\bracket{$3}$4"). //Replace [....] with \bracket{....}; Level 8
replace(/\u2610/g, "\\Box{}").
replace(/\u25BA/g, "\\Rightarrow{}").
replace(/\u25C4/g, "\\Leftrightarrow{}").
replace(/\u2192/g, "\\rightarrow{}").
replace(/\u2190/g, "\\leftarrow{}").
replace(/\u2191/g, "\\uparrow{}").
replace(/\u2193/g, "\\downarrow{}").
replace(/\u205E/g, "\\vdots{}").
replace(/\261/g, "\\pm{}").
replace(/\u2260/g, "\\neq{}").
replace(/\u2264/g, "\\le{}").
replace(/\u2265/g, "\\ge{}").
replace(/\u00F7/g, "\\div{}").
replace(/\u00D7/g, "\\times{}").
replace(/\u2248/g, "\\approx{}").
replace(/\u221E/g, "\\infty{}").
replace(/\u222B/g, "\\int{}").
replace(/\u221A/g, "\\sqrt{}").
replace(/\u2020/g, "\\dagger{}").
replace(/\u2202/g, "\\partial{}").
replace(/\u03B1/g, "\\alpha{}").
replace(/\u03B2/g, "\\beta{}").
replace(/\u00B5/g, "\\mu{}").
replace(/\u03B4/g, "\\delta{}").
replace(/\u03B50/g, "\\varepsilon{}_0"). //eps0 is famous!
replace(/eps0/g, "\\varepsilon{}_0"). //eps0 is famous!
replace(/\u03B5/g, "\\varepsilon{}").
replace(/\u03B7/g, "\\eta{}").
replace(/\u03F5/g, "\\epsilon{}").
replace(/\u03BE/g, "\\xi{}").
replace(/\u03B6/g, "\\zeta{}").
replace(/\u03BB/g, "\\lambda{}").
replace(/\u03BD/g, "\\varrho{}").
replace(/\u03C0/g, "\\pi{}").
replace(/\u03C9/g, "\\omega{}").
replace(/\u03C1/g, "\\rho{}").
replace(/\u03C3/g, "\\sigma{}").
replace(/\u03C4/g, "\\tau{}").
replace(/\u03C7/g, "\\chi{}").
replace(/\u03D2/g, "\\Upsilon{}").
replace(/\u03B3/g, "\\gamma{}").
replace(/\u03C8/g, "\\psi{}").
replace(/\u2211/g, "\\Sigma{}").
replace(/\u0393/g, "\\Gamma{}").
replace(/\u0394/g, "\\Delta{}").
replace(/\u2207/g, "\\nabla {}").
replace(/\u03A0/g, "\\Pi{}").
replace(/\u03A9/g, "\\Omega{}").
replace(/\u03A6/g, "\\Phi{}").
replace(/\u03B8/g, "\\Theta{}").
replace(/\u00A7/g, "\\S{}").
replace(/\u2660/g, "\\spadesuit{}").
replace(/\u2663/g, "\\clubsuit{}").
replace(/\u2665/g, "\\heartsuit{}").
replace(/\u2666/g, "\\Diamond{}").
replace(/\u25CA/g, "\\diamondsuit{}").
replace(/\u25CB/g, "\\circ{}").
replace(/\u25CF/g, "\\bullet{}").
replace(/\u00B9/g, "^1{}").
replace(/\u00B2/g, "^2{}").
replace(/\u00B3/g, "^3{}").
replace(/\u215B/g, "\\left.1\\middle/8\\right.{}").
replace(/\u215B/g, "\\left.1\\middle/8\\right.{}").
replace(/\u215B/g, "\\left.1\\middle/8\\right.{}").
replace(/\u2155/g, "\\left.1\\middle/5\\right.{}").
replace(/\u2159/g, "\\left.1\\middle/6\\right.{}").
replace(/\u00BC/g, "\\left.1\\middle/4\\right.{}").
replace(/\u2153/g, "\\left.1\\middle/3\\right.{}").
replace(/\u215C/g, "\\left.3\\middle/8\\right.{}").
replace(/\u2156/g, "\\left.2\\middle/5\\right.{}").
replace(/\u00BD/g, "\\left.1\\middle/2\\right.{}").
replace(/\u2157/g, "\\left.3\\middle/5\\right.{}").
replace(/\u215D/g, "\\left.5\\middle/8\\right.{}").
replace(/\u2154/g, "\\left.2\\middle/3\\right.{}").
replace(/\u00BE/g, "\\left.3\\middle/4\\right.{}").
replace(/\u2158/g, "\\left.4\\middle/5\\right.{}").
replace(/\u215A/g, "\\left.5\\middle/6\\right.{}").
replace(/\u215E/g, "\\left.7\\middle/8\\right.{}").
replace(/\u214D/g, "\\left.A\\middle/S\\right.{}");
}
}