Fixing the usage of symbols in text.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
20c1ed005e
commit
7a80455e25
3 changed files with 27 additions and 18 deletions
|
@ -100,10 +100,11 @@ function functionToLatex(f, args) {
|
||||||
/**
|
/**
|
||||||
* Creates a latex variable from a variable.
|
* Creates a latex variable from a variable.
|
||||||
*
|
*
|
||||||
* @param {string} vari - variable to convert
|
* @param {string} vari - variable text to convert
|
||||||
|
* @param {bool} wrapIn$ - checks whether the escaped chars should be escaped
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function variable(vari) {
|
function variable(vari, wrapIn$ = false) {
|
||||||
let unicodechars = ["α","β","γ","δ","ε","ζ","η",
|
let unicodechars = ["α","β","γ","δ","ε","ζ","η",
|
||||||
"π","θ","κ","λ","μ","ξ","ρ",
|
"π","θ","κ","λ","μ","ξ","ρ",
|
||||||
"ς","σ","τ","φ","χ","ψ","ω",
|
"ς","σ","τ","φ","χ","ψ","ω",
|
||||||
|
@ -124,8 +125,13 @@ function variable(vari) {
|
||||||
"{}^{7}","{}^{8}","{}^{9}","{}^{0}","{}_{1}","{}_{2}","{}_{3}",
|
"{}^{7}","{}^{8}","{}^{9}","{}^{0}","{}_{1}","{}_{2}","{}_{3}",
|
||||||
"{}_{4}","{}_{5}","{}_{6}","{}_{7}","{}_{8}","{}_{9}","{}_{0}",
|
"{}_{4}","{}_{5}","{}_{6}","{}_{7}","{}_{8}","{}_{9}","{}_{0}",
|
||||||
"\\pi"]
|
"\\pi"]
|
||||||
|
if(wrapIn$)
|
||||||
|
for(let i = 0; i < unicodechars.length; i++) {
|
||||||
|
if(vari.includes(unicodechars[i]))
|
||||||
|
vari = vari.replace(new RegExp(unicodechars[i], 'g'), '$'+equivalchars[i]+'$')
|
||||||
|
}
|
||||||
|
else
|
||||||
for(let i = 0; i < unicodechars.length; i++) {
|
for(let i = 0; i < unicodechars.length; i++) {
|
||||||
//console.log(vari, unicodechars[i], equivalchars[i]);
|
|
||||||
if(vari.includes(unicodechars[i]))
|
if(vari.includes(unicodechars[i]))
|
||||||
vari = vari.replace(new RegExp(unicodechars[i], 'g'), equivalchars[i])
|
vari = vari.replace(new RegExp(unicodechars[i], 'g'), equivalchars[i])
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,16 +59,21 @@ class Text extends Common.DrawableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
latexMarkupText() {
|
latexMarkupText() {
|
||||||
let txt = Latex.variable(this.text)
|
// Check whether the text contains latex escaped elements.
|
||||||
|
let txt = []
|
||||||
|
this.text.split('$$').forEach(function(t) { txt = txt.concat(Latex.variable(t, true).replace(/\$\$/g, '').split('$')) })
|
||||||
|
let newTxt = txt[0]
|
||||||
let i
|
let i
|
||||||
for(i = 0; txt.includes('$$'); i++)
|
// Split between normal text and latex escaped.
|
||||||
|
for(i = 0; i < txt.length-1; i++)
|
||||||
if(i & 0x01) // Every odd number
|
if(i & 0x01) // Every odd number
|
||||||
txt = txt.replace('$$', '\\textsf{')
|
newTxt += '\\textsf{'+Latex.variable(txt[i+1])
|
||||||
else
|
else
|
||||||
txt = txt.replace('$$', '}')
|
newTxt += '}'+txt[i+1]
|
||||||
if(i & 0x01) // Finished by a }
|
// Finished by a }
|
||||||
txt += "{"
|
if(i & 0x01)
|
||||||
return txt
|
newTxt += "{"
|
||||||
|
return newTxt
|
||||||
}
|
}
|
||||||
|
|
||||||
getLatexString() {
|
getLatexString() {
|
||||||
|
|
|
@ -35,7 +35,6 @@ If not found, it will send an alert to the user.
|
||||||
"""
|
"""
|
||||||
LATEX_PATH = which('latex')
|
LATEX_PATH = which('latex')
|
||||||
DVIPNG_PATH = which('dvipng')
|
DVIPNG_PATH = which('dvipng')
|
||||||
#subprocess.run(["ls", "-l", "/dev/null"], capture_output=True)
|
|
||||||
|
|
||||||
DEFAULT_LATEX_DOC = Template(r"""
|
DEFAULT_LATEX_DOC = Template(r"""
|
||||||
\documentclass[]{minimal}
|
\documentclass[]{minimal}
|
||||||
|
@ -85,7 +84,7 @@ class Latex(QObject):
|
||||||
"""
|
"""
|
||||||
Prepares and renders a latex string into a png file.
|
Prepares and renders a latex string into a png file.
|
||||||
"""
|
"""
|
||||||
markup_hash = hash(latex_markup)
|
markup_hash = "render"+str(hash(latex_markup))
|
||||||
export_path = path.join(self.tempdir.name, f'{markup_hash}_{int(font_size)}_{color.rgb()}')
|
export_path = path.join(self.tempdir.name, f'{markup_hash}_{int(font_size)}_{color.rgb()}')
|
||||||
if self.latexSupported and not path.exists(export_path + ".png"):
|
if self.latexSupported and not path.exists(export_path + ".png"):
|
||||||
print("Rendering", latex_markup, export_path)
|
print("Rendering", latex_markup, export_path)
|
||||||
|
@ -119,14 +118,13 @@ class Latex(QObject):
|
||||||
|
|
||||||
def convert_latex_to_dvi(self, export_path: str):
|
def convert_latex_to_dvi(self, export_path: str):
|
||||||
"""
|
"""
|
||||||
Converts a DVI file to a PNG file.
|
Converts a TEX file to a DVI file.
|
||||||
"""
|
"""
|
||||||
self.run([
|
self.run([
|
||||||
LATEX_PATH,
|
LATEX_PATH,
|
||||||
export_path + ".tex"
|
export_path + ".tex"
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def convert_dvi_to_png(self, dvi_path: str, export_path: str, font_size: float, color: QColor):
|
def convert_dvi_to_png(self, dvi_path: str, export_path: str, font_size: float, color: QColor):
|
||||||
"""
|
"""
|
||||||
Converts a DVI file to a PNG file.
|
Converts a DVI file to a PNG file.
|
||||||
|
|
Loading…
Reference in a new issue