feat(maths): latex authoring system
This commit is contained in:
parent
c37b88ff88
commit
12a1679f36
12 changed files with 1401 additions and 20 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -19,3 +19,7 @@ compile_commands.json
|
|||
CTestTestfile.cmake
|
||||
_deps
|
||||
bin
|
||||
ignored
|
||||
|
||||
maths/*.pdf
|
||||
maths/*.synctex.gz
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx pretty-quick --staged
|
||||
node .husky/scripts/cleanMaths.js
|
||||
|
|
58
.husky/scripts/cleanMaths.js
Normal file
58
.husky/scripts/cleanMaths.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { pdfToPng } = require('pdf-to-png-converter');
|
||||
const Jimp = require('jimp');
|
||||
|
||||
const mathsDir = path.resolve(__dirname, '..', '..', 'maths');
|
||||
|
||||
const cropBuffer = buffer =>
|
||||
new Promise((resolve, reject) => {
|
||||
Jimp.read(buffer)
|
||||
.then(cropped => {
|
||||
cropped.autocrop();
|
||||
|
||||
new Jimp(
|
||||
cropped.getWidth() + 100,
|
||||
cropped.getHeight() + 100,
|
||||
'#ffffff',
|
||||
async (err, image) => {
|
||||
if (err) reject(err);
|
||||
|
||||
image.blit(cropped, 50, 50);
|
||||
|
||||
resolve(await image.getBufferAsync(Jimp.MIME_PNG));
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(err => reject(err));
|
||||
});
|
||||
|
||||
fs.readdirSync(mathsDir).forEach(file => {
|
||||
const [fileName, fileExtension] = file.split('.');
|
||||
const filePath = path.join(mathsDir, file);
|
||||
|
||||
if (file.endsWith('.pdf')) {
|
||||
pdfToPng(filePath, {
|
||||
viewportScale: 2
|
||||
}).then(async output => {
|
||||
const pageCount = output.length;
|
||||
|
||||
if (pageCount > 1)
|
||||
output.forEach(async (page, i) =>
|
||||
fs.writeFileSync(
|
||||
path.join(mathsDir, `${fileName}-${i + 1}.png`),
|
||||
await cropBuffer(page.content)
|
||||
)
|
||||
);
|
||||
else
|
||||
fs.writeFileSync(
|
||||
path.join(mathsDir, `${fileName}.png`),
|
||||
await cropBuffer(output[0].content)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (fileExtension !== 'tex' && fileExtension !== 'png' && fileExtension !== 'cls') {
|
||||
fs.rmSync(filePath);
|
||||
}
|
||||
});
|
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"recommendations": ["James-Yu.latex-workshop"]
|
||||
}
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
|
@ -1,5 +1,4 @@
|
|||
{
|
||||
"java.project.sourcePaths": ["java"],
|
||||
"files.exclude": {
|
||||
"**/.git": true,
|
||||
"**/.svn": true,
|
||||
|
@ -34,5 +33,8 @@
|
|||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"streambuf": "cpp"
|
||||
}
|
||||
},
|
||||
"latex-workshop.latex.autoBuild.run": "onSave",
|
||||
"latex-workshop.latex.autoClean.run": "onBuilt",
|
||||
"latex-workshop.latex.search.rootFiles.include": ["**/*.tex", "root.tex"]
|
||||
}
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
from math import e
|
||||
from cmath import e, sqrt
|
||||
from _helpers import floatInput
|
||||
|
||||
def sin(radians):
|
||||
x = radians
|
||||
return (((e ** (1j * x)) - (e ** -(1j * x))) / 2j).real
|
||||
i = sqrt(-1)
|
||||
|
||||
def cos(radians):
|
||||
x = radians
|
||||
return (((e ** (1j * x)) + (e ** -(1j * x))) / 2).real
|
||||
compute = lambda numerator, denominator: (numerator / denominator).real
|
||||
sin = lambda x: compute(pow(e, i * x) - pow(e, -i * x), 2 * i)
|
||||
cos = lambda x: compute(pow(e, i * x) + pow(e, -i * x), 2)
|
||||
tan = lambda x: compute(pow(e, i * x) - pow(e, -i * x), i * (pow(e, i * x) + pow(e, -i * x)))
|
||||
radians = floatInput("Please enter an amount of radians: ")
|
||||
|
||||
def tan(radians):
|
||||
x = radians
|
||||
return (((e ** (1j * x)) - (e ** -(1j * x))) / (1j * ((e ** (1j * x)) + (e ** -(1j * x))))).real
|
||||
print(f"""
|
||||
sin({radians}) = {sin(radians)})
|
||||
cos({radians}) = {cos(radians)}
|
||||
tan({radians}) = {tan(radians)}
|
||||
|
||||
a = floatInput("Please enter an amount of radians: ")
|
||||
|
||||
print("""Where x = %i:
|
||||
sin(x) = %f
|
||||
cos(x) = %f
|
||||
tan(x) = %f
|
||||
""" % (a, sin(a), cos(a), tan(a)))
|
||||
csc({radians}) = {1 / sin(radians)}
|
||||
sec({radians}) = {1 / cos(radians)}
|
||||
cot({radians}) = {1 / tan(radians)}""")
|
||||
|
|
|
@ -5,4 +5,4 @@ def floatInput(text):
|
|||
x = float(input(text))
|
||||
return x
|
||||
except ValueError:
|
||||
print('You must input a float integer!\n')
|
||||
print('You must input a float!\n')
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 237 KiB After Width: | Height: | Size: 23 KiB |
12
maths/nth root.tex
Normal file
12
maths/nth root.tex
Normal file
|
@ -0,0 +1,12 @@
|
|||
\documentclass{style}
|
||||
\usepackage{amsmath}
|
||||
\begin{document}
|
||||
\begin{gather*}
|
||||
f(x) = x^k - s \\
|
||||
f'(x) = kx^{k - 1}
|
||||
\end{gather*}
|
||||
|
||||
\begin{gather*}
|
||||
x_{n + 1} = x_n - \frac{x_n^k - s}{kx_n^{k - 1}} = \frac{x_n(k - 1) + sx_n^{1 - k}}{k}
|
||||
\end{gather*}
|
||||
\end{document}
|
3
maths/style.cls
Normal file
3
maths/style.cls
Normal file
|
@ -0,0 +1,3 @@
|
|||
\ProvidesClass{style}
|
||||
\LoadClass[17pt]{extarticle}
|
||||
\pagenumbering{gobble}
|
|
@ -8,6 +8,8 @@
|
|||
"commitizen": "^4.2.4",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
"husky": "^7.0.4",
|
||||
"jimp": "^0.16.1",
|
||||
"pdf-to-png-converter": "^1.0.0",
|
||||
"prettier": "^2.5.1",
|
||||
"pretty-quick": "^3.1.3"
|
||||
}
|
||||
|
|
1299
pnpm-lock.yaml
1299
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue