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.
|
||||
*
|
||||
* @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}
|
||||
*/
|
||||
function variable(vari) {
|
||||
function variable(vari, wrapIn$ = false) {
|
||||
let unicodechars = ["α","β","γ","δ","ε","ζ","η",
|
||||
"π","θ","κ","λ","μ","ξ","ρ",
|
||||
"ς","σ","τ","φ","χ","ψ","ω",
|
||||
|
@ -124,8 +125,13 @@ function variable(vari) {
|
|||
"{}^{7}","{}^{8}","{}^{9}","{}^{0}","{}_{1}","{}_{2}","{}_{3}",
|
||||
"{}_{4}","{}_{5}","{}_{6}","{}_{7}","{}_{8}","{}_{9}","{}_{0}",
|
||||
"\\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++) {
|
||||
//console.log(vari, unicodechars[i], equivalchars[i]);
|
||||
if(vari.includes(unicodechars[i]))
|
||||
vari = vari.replace(new RegExp(unicodechars[i], 'g'), equivalchars[i])
|
||||
}
|
||||
|
|
|
@ -59,16 +59,21 @@ class Text extends Common.DrawableObject {
|
|||
}
|
||||
|
||||
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
|
||||
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
|
||||
txt = txt.replace('$$', '\\textsf{')
|
||||
newTxt += '\\textsf{'+Latex.variable(txt[i+1])
|
||||
else
|
||||
txt = txt.replace('$$', '}')
|
||||
if(i & 0x01) // Finished by a }
|
||||
txt += "{"
|
||||
return txt
|
||||
newTxt += '}'+txt[i+1]
|
||||
// Finished by a }
|
||||
if(i & 0x01)
|
||||
newTxt += "{"
|
||||
return newTxt
|
||||
}
|
||||
|
||||
getLatexString() {
|
||||
|
|
|
@ -35,7 +35,6 @@ If not found, it will send an alert to the user.
|
|||
"""
|
||||
LATEX_PATH = which('latex')
|
||||
DVIPNG_PATH = which('dvipng')
|
||||
#subprocess.run(["ls", "-l", "/dev/null"], capture_output=True)
|
||||
|
||||
DEFAULT_LATEX_DOC = Template(r"""
|
||||
\documentclass[]{minimal}
|
||||
|
@ -85,7 +84,7 @@ class Latex(QObject):
|
|||
"""
|
||||
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()}')
|
||||
if self.latexSupported and not path.exists(export_path + ".png"):
|
||||
print("Rendering", latex_markup, export_path)
|
||||
|
@ -119,14 +118,13 @@ class Latex(QObject):
|
|||
|
||||
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([
|
||||
LATEX_PATH,
|
||||
export_path + ".tex"
|
||||
])
|
||||
|
||||
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue