math-exercises 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/exercises/math/calculLitteral/distributivity/simpleDistributivity.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/distributivity/simpleDistributivity.js +0 -1
- package/lib/exercises/math/calculLitteral/factorisation/factoType1Exercise.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/factorisation/factoType1Exercise.js +0 -2
- package/lib/exercises/math/dataRepresentations/index.d.ts +0 -1
- package/lib/exercises/math/dataRepresentations/index.d.ts.map +1 -1
- package/lib/exercises/math/dataRepresentations/index.js +1 -1
- package/lib/exercises/math/powers/powersProduct.d.ts +2 -1
- package/lib/exercises/math/powers/powersProduct.d.ts.map +1 -1
- package/lib/exercises/math/powers/powersProduct.js +15 -4
- package/lib/exercises/math/probaStat/basicStats/calculateFrequency.d.ts +10 -0
- package/lib/exercises/math/probaStat/basicStats/calculateFrequency.d.ts.map +1 -0
- package/lib/exercises/math/probaStat/basicStats/calculateFrequency.js +100 -0
- package/lib/exercises/math/probaStat/basicStats/index.d.ts +2 -0
- package/lib/exercises/math/probaStat/basicStats/index.d.ts.map +1 -0
- package/lib/exercises/math/probaStat/basicStats/index.js +1 -0
- package/lib/exercises/math/probaStat/index.d.ts +1 -0
- package/lib/exercises/math/probaStat/index.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/index.js +1 -0
- package/lib/exercises/math/sequences/arithmetic/arithmeticFirstTermsSum.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/arithmeticFirstTermsSum.js +19 -8
- package/lib/exercises/math/sequences/arithmetic/firstIntegersSum.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/firstIntegersSum.js +52 -4
- package/lib/exercises/math/sequences/geometric/geometricFirstTermsGeneralSum.d.ts.map +1 -1
- package/lib/exercises/math/sequences/geometric/geometricFirstTermsGeneralSum.js +20 -9
- package/lib/exercises/math/sequences/geometric/geometricFirstTermsSum.d.ts.map +1 -1
- package/lib/exercises/math/sequences/geometric/geometricFirstTermsSum.js +19 -14
- package/lib/index.d.ts +6 -6
- package/lib/playground.d.ts +1 -1
- package/lib/playground.d.ts.map +1 -1
- package/lib/playground.js +1 -14
- package/lib/tests/exoTest.d.ts +7 -0
- package/lib/tests/exoTest.d.ts.map +1 -0
- package/lib/tests/exoTest.js +46 -0
- package/lib/tests/exosTest.d.ts +3 -0
- package/lib/tests/exosTest.d.ts.map +1 -0
- package/lib/tests/exosTest.js +44 -0
- package/lib/tests/global.test.d.ts +2 -0
- package/lib/tests/global.test.d.ts.map +1 -0
- package/lib/tests/global.test.js +8 -0
- package/lib/tests/latexParser.test.d.ts +2 -0
- package/lib/tests/latexParser.test.d.ts.map +1 -0
- package/lib/tests/latexParser.test.js +51 -0
- package/lib/tests/manyPdfExos.test.d.ts +2 -0
- package/lib/tests/manyPdfExos.test.d.ts.map +1 -0
- package/lib/tests/manyPdfExos.test.js +19 -0
- package/lib/tests/ml.test.d.ts +2 -0
- package/lib/tests/ml.test.d.ts.map +1 -0
- package/lib/tests/ml.test.js +11 -0
- package/lib/tests/multiplySimplify.test.d.ts +2 -0
- package/lib/tests/multiplySimplify.test.d.ts.map +1 -0
- package/lib/tests/multiplySimplify.test.js +32 -0
- package/lib/tests/pdfExo.test.d.ts +2 -0
- package/lib/tests/pdfExo.test.d.ts.map +1 -0
- package/lib/tests/pdfExo.test.js +10 -0
- package/lib/tests/pdfs/buildPDFForExercise.d.ts +3 -0
- package/lib/tests/pdfs/buildPDFForExercise.d.ts.map +1 -0
- package/lib/tests/pdfs/buildPDFForExercise.js +108 -0
- package/lib/tests/pdfs/formatMdToLatex.d.ts +2 -0
- package/lib/tests/pdfs/formatMdToLatex.d.ts.map +1 -0
- package/lib/tests/pdfs/formatMdToLatex.js +9 -0
- package/lib/tests/pdfs/mdCodeToLatex.d.ts +2 -0
- package/lib/tests/pdfs/mdCodeToLatex.d.ts.map +1 -0
- package/lib/tests/pdfs/mdCodeToLatex.js +20 -0
- package/lib/tests/pdfs/mdTableToLatexTabular.d.ts +2 -0
- package/lib/tests/pdfs/mdTableToLatexTabular.d.ts.map +1 -0
- package/lib/tests/pdfs/mdTableToLatexTabular.js +30 -0
- package/lib/tests/pdfs/quizPdfHeader.d.ts +9 -0
- package/lib/tests/pdfs/quizPdfHeader.d.ts.map +1 -0
- package/lib/tests/pdfs/quizPdfHeader.js +44 -0
- package/lib/tests/pdfs/quizPdfPreambule.d.ts +2 -0
- package/lib/tests/pdfs/quizPdfPreambule.d.ts.map +1 -0
- package/lib/tests/pdfs/quizPdfPreambule.js +76 -0
- package/lib/tests/questionTest.d.ts +6 -0
- package/lib/tests/questionTest.d.ts.map +1 -0
- package/lib/tests/questionTest.js +156 -0
- package/lib/tests/simplify.test.d.ts +2 -0
- package/lib/tests/simplify.test.d.ts.map +1 -0
- package/lib/tests/simplify.test.js +32 -0
- package/lib/tests/singleExo.test.d.ts +2 -0
- package/lib/tests/singleExo.test.d.ts.map +1 -0
- package/lib/tests/singleExo.test.js +9 -0
- package/lib/tests/xl.test.d.ts +2 -0
- package/lib/tests/xl.test.d.ts.map +1 -0
- package/lib/tests/xl.test.js +11 -0
- package/package.json +9 -8
- package/lib/server.js.map +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { latexTester } from "../latexTester.js";
|
|
2
|
+
import { questionTest } from "./questionTest.js";
|
|
3
|
+
export const exoTest = (exo) => {
|
|
4
|
+
//instruction
|
|
5
|
+
//correction
|
|
6
|
+
//hint
|
|
7
|
+
//answer
|
|
8
|
+
//propositions
|
|
9
|
+
console.log(exo.id);
|
|
10
|
+
let qcmTime = -1;
|
|
11
|
+
let veaTime = -1;
|
|
12
|
+
let generatorTime = -1;
|
|
13
|
+
if (!exo.label.length)
|
|
14
|
+
throw new Error(`exo ${exo.id} has no label`);
|
|
15
|
+
if (!latexTester(exo.label))
|
|
16
|
+
throw new Error(`exo ${exo.id} has invalid label`);
|
|
17
|
+
let before = Date.now();
|
|
18
|
+
console.log("generate questions : ", exo.id);
|
|
19
|
+
const questions = exo.generator(30);
|
|
20
|
+
let after = Date.now();
|
|
21
|
+
generatorTime = after - before;
|
|
22
|
+
if (exo.answerType !== "free" && exo.answerType !== "GGB") {
|
|
23
|
+
if (!exo.getPropositions)
|
|
24
|
+
throw new Error(`exo ${exo.id} has no getPropositions`);
|
|
25
|
+
}
|
|
26
|
+
if (exo.answerType !== "QCM" &&
|
|
27
|
+
exo.answerType !== "QCU" &&
|
|
28
|
+
exo.answerType !== "GGB") {
|
|
29
|
+
if (!exo.isAnswerValid)
|
|
30
|
+
throw new Error(`exo ${exo.id} has no isAnswerValid`);
|
|
31
|
+
}
|
|
32
|
+
if (exo.answerType === "GGB") {
|
|
33
|
+
if (!exo.isGGBAnswerValid)
|
|
34
|
+
throw new Error(`exo ${exo.id} has no isGGBAnswerValid`);
|
|
35
|
+
}
|
|
36
|
+
questions.forEach((question) => {
|
|
37
|
+
const times = questionTest(exo, question);
|
|
38
|
+
qcmTime = times.qcmTime;
|
|
39
|
+
veaTime = times.veaTime;
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
generatorTime,
|
|
43
|
+
qcmTime,
|
|
44
|
+
veaTime,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exosTest.d.ts","sourceRoot":"","sources":["../../src/tests/exosTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAQvD,eAAO,MAAM,QAAQ,SAAU,QAAQ,EAAE,SAsDxC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { exoTest } from "./exoTest.js";
|
|
2
|
+
export const exosTest = (exos) => {
|
|
3
|
+
const questionsGenerationTimes = [];
|
|
4
|
+
let worstQuestionGenerationTime = { exoId: "", time: 0 };
|
|
5
|
+
const qcmGenerationTimes = [];
|
|
6
|
+
let worstQCMGenerationTime = { exoId: "", time: 0 };
|
|
7
|
+
const veaTimes = [];
|
|
8
|
+
let worstVEATime = { exoId: "", time: 0 };
|
|
9
|
+
const ggbVeaTimes = [];
|
|
10
|
+
let worstGGBVEATime = { exoId: "", time: 0 };
|
|
11
|
+
// const allExos = [MathExercises.inflexionPointQuadrinomials];
|
|
12
|
+
exos.forEach((exo) => {
|
|
13
|
+
console.log(exo.id);
|
|
14
|
+
try {
|
|
15
|
+
const times = exoTest(exo);
|
|
16
|
+
veaTimes.push(times.veaTime);
|
|
17
|
+
questionsGenerationTimes.push(times.generatorTime);
|
|
18
|
+
qcmGenerationTimes.push(times.qcmTime);
|
|
19
|
+
if (times.veaTime > worstVEATime.time)
|
|
20
|
+
worstVEATime = { exoId: exo.id, time: times.veaTime };
|
|
21
|
+
if (times.generatorTime > worstQuestionGenerationTime.time)
|
|
22
|
+
worstQuestionGenerationTime = {
|
|
23
|
+
exoId: exo.id,
|
|
24
|
+
time: times.generatorTime,
|
|
25
|
+
};
|
|
26
|
+
if (times.qcmTime > worstQCMGenerationTime.time)
|
|
27
|
+
worstQCMGenerationTime = { exoId: exo.id, time: times.qcmTime };
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
console.log(exo.id, err);
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
console.log("average ggbVea", ggbVeaTimes.reduce((acc, curr) => acc + curr, 0) / ggbVeaTimes.length);
|
|
35
|
+
console.log("average vea", veaTimes.reduce((acc, curr) => acc + curr, 0) / veaTimes.length);
|
|
36
|
+
console.log("average qcm", qcmGenerationTimes.reduce((acc, curr) => acc + curr, 0) /
|
|
37
|
+
qcmGenerationTimes.length);
|
|
38
|
+
console.log("average generator", questionsGenerationTimes.reduce((acc, curr) => acc + curr, 0) /
|
|
39
|
+
questionsGenerationTimes.length);
|
|
40
|
+
console.log("worst qcm", worstQCMGenerationTime);
|
|
41
|
+
console.log("worst vea", worstVEATime);
|
|
42
|
+
console.log("worst ggbVea", worstGGBVEATime);
|
|
43
|
+
console.log("worst generator", worstQuestionGenerationTime);
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.test.d.ts","sourceRoot":"","sources":["../../src/tests/global.test.ts"],"names":[],"mappings":"AAKA,OAAO,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as MathExercises from "../exercises/math/index.js";
|
|
2
|
+
import * as PCExercises from "../exercises/pc/index.js";
|
|
3
|
+
import "../prototypesEnhancement.js";
|
|
4
|
+
import { exosTest } from "./exosTest.js";
|
|
5
|
+
const mathExercises = Object.values(MathExercises);
|
|
6
|
+
const pcExercises = Object.values(PCExercises);
|
|
7
|
+
const allExos = [...mathExercises, ...pcExercises];
|
|
8
|
+
exosTest(allExos);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"latexParser.test.d.ts","sourceRoot":"","sources":["../../src/tests/latexParser.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { parseAlgebraic } from "../tree/parsers/latexParser.js";
|
|
2
|
+
const texsThatShouldNotChange = [
|
|
3
|
+
"3",
|
|
4
|
+
"3,14",
|
|
5
|
+
"-4",
|
|
6
|
+
"-1,003",
|
|
7
|
+
"x",
|
|
8
|
+
"-x",
|
|
9
|
+
"3+4",
|
|
10
|
+
"3-9",
|
|
11
|
+
"1,13-33",
|
|
12
|
+
"-1,3432-0,001",
|
|
13
|
+
"3+x",
|
|
14
|
+
"3-x",
|
|
15
|
+
"x+3",
|
|
16
|
+
"x-3",
|
|
17
|
+
"2x+1",
|
|
18
|
+
"1+2x",
|
|
19
|
+
"3x^2+2x+1",
|
|
20
|
+
"x^2+x+1",
|
|
21
|
+
"-x^2-x-1",
|
|
22
|
+
];
|
|
23
|
+
const texsThatShouldChange = [
|
|
24
|
+
{ in: "3\\times x+1", out: "3x+1" },
|
|
25
|
+
{
|
|
26
|
+
in: "3\\times x^2 - 2\\times x +1",
|
|
27
|
+
out: "3x^2-2x+1",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
in: "-3\\times x^2 + (-2)\\times x -1",
|
|
31
|
+
out: "-3x^2-2x-1",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
in: "(-3)\\times x^2 + (-2)\\times x +(-1)",
|
|
35
|
+
out: "-3x^2-2x-1",
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
try {
|
|
39
|
+
for (const tex of texsThatShouldNotChange) {
|
|
40
|
+
if (parseAlgebraic(tex).toTex() !== tex)
|
|
41
|
+
throw new Error(`wrong tex ${tex}`);
|
|
42
|
+
}
|
|
43
|
+
for (const data of texsThatShouldChange) {
|
|
44
|
+
if (parseAlgebraic(data.in).toTex() !== data.out)
|
|
45
|
+
throw new Error(`wrong tex ${data.in}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
console.log(err);
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manyPdfExos.test.d.ts","sourceRoot":"","sources":["../../src/tests/manyPdfExos.test.ts"],"names":[],"mappings":"AAQA,OAAO,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { buildPdfForExercise } from "./pdfs/buildPDFForExercise.js";
|
|
2
|
+
import "../prototypesEnhancement.js";
|
|
3
|
+
import * as MathExercises from "../exercises/math/index.js";
|
|
4
|
+
import * as PCExercises from "../exercises/pc/index.js";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
const mathExercises = Object.values(MathExercises);
|
|
7
|
+
const pcExercises = Object.values(PCExercises);
|
|
8
|
+
try {
|
|
9
|
+
fs.rmSync(__dirname + "/pdfs/dump", { recursive: true, force: true });
|
|
10
|
+
fs.mkdirSync(__dirname + "/pdfs/dump");
|
|
11
|
+
const exos = mathExercises.slice(450, 500);
|
|
12
|
+
for (const exo of exos) {
|
|
13
|
+
buildPdfForExercise(exo);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
console.log(err);
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ml.test.d.ts","sourceRoot":"","sources":["../../src/tests/ml.test.ts"],"names":[],"mappings":"AACA,OAAO,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { exosTest } from "./exosTest.js";
|
|
2
|
+
import "../prototypesEnhancement.js";
|
|
3
|
+
import { mathExercises } from "../index.js";
|
|
4
|
+
const mathExos = Object.values(mathExercises);
|
|
5
|
+
try {
|
|
6
|
+
exosTest(mathExos);
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
console.log(err);
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplySimplify.test.d.ts","sourceRoot":"","sources":["../../src/tests/multiplySimplify.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { sqrt } from "../tree/nodes/functions/sqrtNode.js";
|
|
2
|
+
import { NumberNode } from "../tree/nodes/numbers/numberNode.js";
|
|
3
|
+
import { MultiplyNode, multiply, } from "../tree/nodes/operators/multiplyNode.js";
|
|
4
|
+
const data = [
|
|
5
|
+
{
|
|
6
|
+
in: new MultiplyNode(new NumberNode(1), new NumberNode(2)),
|
|
7
|
+
out: new NumberNode(2),
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
in: new MultiplyNode(new NumberNode(2), new NumberNode(4)),
|
|
11
|
+
out: new NumberNode(8),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
in: new MultiplyNode(new NumberNode(-2), new NumberNode(4)),
|
|
15
|
+
out: new NumberNode(-8),
|
|
16
|
+
},
|
|
17
|
+
{ in: multiply(sqrt(3), sqrt(8)), out: multiply(2, sqrt(6)) },
|
|
18
|
+
];
|
|
19
|
+
try {
|
|
20
|
+
for (const d of data) {
|
|
21
|
+
console.log(d.in.toTex());
|
|
22
|
+
const simplified = d.in.simplify();
|
|
23
|
+
console.log(simplified);
|
|
24
|
+
if (!simplified.equals(d.out)) {
|
|
25
|
+
throw new Error(`Expected ${d.out.toTex()} but got ${simplified.toTex()}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
console.log(err);
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfExo.test.d.ts","sourceRoot":"","sources":["../../src/tests/pdfExo.test.ts"],"names":[],"mappings":"AAeA,OAAO,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { pointFromParametricLine, } from "../exercises/math/index.js";
|
|
2
|
+
import { buildPdfForExercise } from "./pdfs/buildPDFForExercise.js";
|
|
3
|
+
import "../prototypesEnhancement.js";
|
|
4
|
+
try {
|
|
5
|
+
buildPdfForExercise(pointFromParametricLine);
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
console.log(err);
|
|
9
|
+
throw err;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildPDFForExercise.d.ts","sourceRoot":"","sources":["../../../src/tests/pdfs/buildPDFForExercise.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAyB,MAAM,6BAA6B,CAAC;AAE9E,eAAO,MAAM,mBAAmB,QAAS,QAAQ,SAwGhD,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { quizPdfPreambule } from "./quizPdfPreambule.js";
|
|
2
|
+
import { quizPdfHeader } from "./quizPdfHeader.js";
|
|
3
|
+
import { formatMarkdownToLatex } from "./formatMdToLatex.js";
|
|
4
|
+
// import { activities } from "../src/resolvers/activity/query/activities";
|
|
5
|
+
// import { activities } from "@root/resolvers/activity/query/activities";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import latex from "node-latex";
|
|
8
|
+
export const buildPdfForExercise = (exo) => {
|
|
9
|
+
const exoShortName = exo.id;
|
|
10
|
+
const preambule = quizPdfPreambule();
|
|
11
|
+
const questions = exo.generator(10);
|
|
12
|
+
const header = quizPdfHeader({
|
|
13
|
+
title: exoShortName,
|
|
14
|
+
isCorrection: true,
|
|
15
|
+
});
|
|
16
|
+
let content = "";
|
|
17
|
+
questions.forEach((question, index) => {
|
|
18
|
+
let propositions = [];
|
|
19
|
+
content += `\n\n \\textbf{Question ${index + 1}} \n\n`;
|
|
20
|
+
const imgRegex = /!\[.*?\]\((.*?)\)/g;
|
|
21
|
+
const matches = question.instruction.matchAll(imgRegex);
|
|
22
|
+
for (const match of matches) {
|
|
23
|
+
question.instruction = question.instruction.replace(match[0], ``);
|
|
24
|
+
}
|
|
25
|
+
const formatted = formatMarkdownToLatex(question.instruction);
|
|
26
|
+
content += `
|
|
27
|
+
${formatted} \n
|
|
28
|
+
`;
|
|
29
|
+
if (exo.answerType !== "GGB") {
|
|
30
|
+
propositions = exo.getPropositions(4, {
|
|
31
|
+
answer: question.answer,
|
|
32
|
+
...question.identifiers,
|
|
33
|
+
});
|
|
34
|
+
const shouldSpread = exo.pdfOptions?.shouldSpreadPropositions;
|
|
35
|
+
if (!shouldSpread)
|
|
36
|
+
content += `
|
|
37
|
+
\\setlength{\\columnseprule}{0pt}
|
|
38
|
+
\\begin{multicols}{2}
|
|
39
|
+
`;
|
|
40
|
+
const letters = ["A", "B", "C", "D"];
|
|
41
|
+
propositions.forEach((proposition, index) => {
|
|
42
|
+
const format = proposition.format;
|
|
43
|
+
if (format === "raw") {
|
|
44
|
+
content += `\\textit{${letters[index]})} \\quad ${proposition.statement} \n\n`;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
content += `\\textit{${letters[index]})} \\quad $${proposition.statement}$ \n\n`;
|
|
48
|
+
}
|
|
49
|
+
if (!shouldSpread && (index === 0 || index === 2))
|
|
50
|
+
content += "\\vspace{0.2cm}";
|
|
51
|
+
if (!shouldSpread && index === 1)
|
|
52
|
+
content += "\\columnbreak";
|
|
53
|
+
});
|
|
54
|
+
if (!shouldSpread)
|
|
55
|
+
content += `
|
|
56
|
+
\\end{multicols}
|
|
57
|
+
\\setlength{\\columnseprule}{0.5pt}
|
|
58
|
+
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
content += "\\begin{correctionColored}";
|
|
62
|
+
content += "\\textbf{Correction : } ";
|
|
63
|
+
if (question.correction) {
|
|
64
|
+
content += formatMarkdownToLatex(question.correction);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (exo.answerType === "GGB") {
|
|
68
|
+
content += "Correction GGB";
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const answers = propositions.filter((prop) => prop.isRightAnswer);
|
|
72
|
+
answers?.forEach((ans) => {
|
|
73
|
+
content +=
|
|
74
|
+
ans.format === "raw" ? ans.statement : `$${ans.statement}$`;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
content += "\\end{correctionColored}";
|
|
79
|
+
content += "{\\color{lightgray}\\par\\hrulefill}";
|
|
80
|
+
});
|
|
81
|
+
const endDocument = `
|
|
82
|
+
\\end{multicols*}
|
|
83
|
+
\\end{document}
|
|
84
|
+
`;
|
|
85
|
+
const file = `${preambule}
|
|
86
|
+
${header}
|
|
87
|
+
${content}
|
|
88
|
+
${endDocument}`;
|
|
89
|
+
fs.appendFileSync(__dirname + `/dump/${exoShortName}.tex`, `${file}`);
|
|
90
|
+
const input = fs.createReadStream(__dirname + `/dump/${exoShortName}.tex`);
|
|
91
|
+
const output = fs.createWriteStream(__dirname + `/dump/${exoShortName}.pdf`);
|
|
92
|
+
//@ts-ignore
|
|
93
|
+
const pdf = latex(input, { args: ["-shell-escape"] });
|
|
94
|
+
try {
|
|
95
|
+
pdf.pipe(output);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
console.log("pdf pipe err", exoShortName, err);
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
pdf.on("error", async (err) => {
|
|
102
|
+
console.log("pdf err", err, exoShortName);
|
|
103
|
+
// fs.unlink(__dirname + `/dump/${exoShortName}.pdf`, function (err) {});
|
|
104
|
+
// fs.unlink(__dirname + `/dump/${exoShortName}.tex`, function (err) {});
|
|
105
|
+
throw err;
|
|
106
|
+
});
|
|
107
|
+
pdf.on("finish", async () => { });
|
|
108
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatMdToLatex.d.ts","sourceRoot":"","sources":["../../../src/tests/pdfs/formatMdToLatex.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,SAAU,MAAM,WAMjD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { mdCodeToLatex } from "./mdCodeToLatex.js";
|
|
2
|
+
import { mdTableToLatexTabular } from "./mdTableToLatexTabular.js";
|
|
3
|
+
export const formatMarkdownToLatex = (text) => {
|
|
4
|
+
const format = text
|
|
5
|
+
.replaceAll("\\left\\{", "\\left\\lbrace")
|
|
6
|
+
.replaceAll("\\\\", "\\tabularnewline ")
|
|
7
|
+
.replaceAll("€", "\\euro");
|
|
8
|
+
return mdCodeToLatex(mdTableToLatexTabular(format));
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdCodeToLatex.d.ts","sourceRoot":"","sources":["../../../src/tests/pdfs/mdCodeToLatex.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,SAAU,MAAM,WAoBzC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const mdCodeToLatex = (text) => {
|
|
2
|
+
let res = text;
|
|
3
|
+
//finds things that starts with ``` and ends with ```
|
|
4
|
+
const re = /```[\s\S]*?```/g;
|
|
5
|
+
let match;
|
|
6
|
+
while ((match = re.exec(text)) != null) {
|
|
7
|
+
const content = match[0]
|
|
8
|
+
.replaceAll("```", "")
|
|
9
|
+
.split("\n")
|
|
10
|
+
.filter((n) => !!n)
|
|
11
|
+
.join("\n");
|
|
12
|
+
res =
|
|
13
|
+
res.slice(0, match.index) +
|
|
14
|
+
`$\\hspace{1cm}$ \\begin{lstlisting} \n` +
|
|
15
|
+
content +
|
|
16
|
+
"\\end{lstlisting} \n" +
|
|
17
|
+
res.slice(match.index + match[0].length);
|
|
18
|
+
}
|
|
19
|
+
return res;
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdTableToLatexTabular.d.ts","sourceRoot":"","sources":["../../../src/tests/pdfs/mdTableToLatexTabular.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,SAAU,MAAM,WAwBjD,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const mdTableToLatexTabular = (text) => {
|
|
2
|
+
let res = text;
|
|
3
|
+
//finds things that starts with <!-- table --> and ends with <!-- !table -->
|
|
4
|
+
const re = /<!-- table -->[\s\S]*?<!-- !table -->/g;
|
|
5
|
+
let match;
|
|
6
|
+
while ((match = re.exec(text)) != null) {
|
|
7
|
+
const content = match[0]
|
|
8
|
+
.replace("<!-- table -->", "")
|
|
9
|
+
.replace("<!-- !table -->", "")
|
|
10
|
+
.split("\n")
|
|
11
|
+
.filter((n) => !!n);
|
|
12
|
+
//2nd row is always |-|-|-|
|
|
13
|
+
content.splice(1, 1);
|
|
14
|
+
const latex = formatMarkdownRows(content);
|
|
15
|
+
const tableWidth = content[0].length;
|
|
16
|
+
const alignement = ("|" + "c").repeat(tableWidth) + "|";
|
|
17
|
+
res =
|
|
18
|
+
res.slice(0, match.index) +
|
|
19
|
+
` \\begin{center}\\begin{tabular}{${alignement}} \n \\hline ` +
|
|
20
|
+
latex +
|
|
21
|
+
"\\tabularnewline \\hline \\end{tabular}\\end{center} " +
|
|
22
|
+
res.slice(match.index + match[0].length);
|
|
23
|
+
}
|
|
24
|
+
return res;
|
|
25
|
+
};
|
|
26
|
+
const formatMarkdownRows = (rows) => {
|
|
27
|
+
return rows
|
|
28
|
+
.map((row) => row.substring(1, row.length - 1).replaceAll("|", " & "))
|
|
29
|
+
.join(" \\tabularnewline \\hline ");
|
|
30
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
soloQuizSessionLink?: string;
|
|
3
|
+
title?: string;
|
|
4
|
+
correctionLink?: string;
|
|
5
|
+
isCorrection?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const quizPdfHeader: ({ title, isCorrection, correctionLink, soloQuizSessionLink, }: Props) => string;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=quizPdfHeader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quizPdfHeader.d.ts","sourceRoot":"","sources":["../../../src/tests/pdfs/quizPdfHeader.ts"],"names":[],"mappings":"AAwBA,KAAK,KAAK,GAAG;IACX,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AACF,eAAO,MAAM,aAAa,kEAKvB,KAAK,WA0BP,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//logo mathlive,
|
|
2
|
+
const escape = (text) => {
|
|
3
|
+
const replacements = {
|
|
4
|
+
"%": "\\%",
|
|
5
|
+
"&": "\\&",
|
|
6
|
+
"#": "\\#",
|
|
7
|
+
_: "\\_",
|
|
8
|
+
"{": "\\{",
|
|
9
|
+
"}": "\\}",
|
|
10
|
+
"\\": "\\textbackslash{}",
|
|
11
|
+
$: "\\$",
|
|
12
|
+
"~": "\\textasciitilde{}",
|
|
13
|
+
"^": "\\textasciicircum{}",
|
|
14
|
+
"`": "\\textasciigrave{}",
|
|
15
|
+
};
|
|
16
|
+
return text.replace(/[%&#_{}\\$~^`]/g, (match) => replacements[match]);
|
|
17
|
+
};
|
|
18
|
+
export const quizPdfHeader = ({ title, isCorrection, correctionLink, soloQuizSessionLink, }) => {
|
|
19
|
+
const escapedTitle = escape(title ?? "");
|
|
20
|
+
return `
|
|
21
|
+
|
|
22
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
23
|
+
%
|
|
24
|
+
% Pour compiler ce fichier, il faut lancer pdfLatex (ou autre) avec le parametre -shell-escape
|
|
25
|
+
% (car certains packages en ont besoin pour obtenir des images issues du web)
|
|
26
|
+
%
|
|
27
|
+
% Si vous ne souhaitez pas utiliser --shell-escape :
|
|
28
|
+
% --- Si des questions affichent des images, il faudra télécharger ces images et utiliser \\includegraphics par exemple
|
|
29
|
+
% --- Sinon, vous pouvez supprimer le footer
|
|
30
|
+
%
|
|
31
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
32
|
+
\\DecimalMathComma
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
\\fancyhead[C]{
|
|
36
|
+
\\begin{large}
|
|
37
|
+
${escapedTitle}${isCorrection ? " - Corrigé" : ""}
|
|
38
|
+
\\end{large}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
\\begin{multicols*}{2}
|
|
42
|
+
|
|
43
|
+
`;
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quizPdfPreambule.d.ts","sourceRoot":"","sources":["../../../src/tests/pdfs/quizPdfPreambule.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,cA2E5B,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const quizPdfPreambule = () => {
|
|
2
|
+
return `\\documentclass[a4paper, 8pt]{article}
|
|
3
|
+
\\usepackage[dvipsnames]{xcolor}
|
|
4
|
+
\\usepackage[utf8]{inputenc}
|
|
5
|
+
\\usepackage[T1]{fontenc}
|
|
6
|
+
\\usepackage[french]{babel}
|
|
7
|
+
|
|
8
|
+
\\usepackage{arev}
|
|
9
|
+
\\usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm,includehead,includefoot]{geometry}
|
|
10
|
+
\\usepackage{eurosym}
|
|
11
|
+
\\usepackage{amstext}
|
|
12
|
+
\\DeclareRobustCommand{\\officialeuro}{%
|
|
13
|
+
\\ifmmode\\expandafter\\text\\fi
|
|
14
|
+
{\\fontencoding{U}\\fontfamily{eurosym}\\selectfont e}}
|
|
15
|
+
|
|
16
|
+
\\usepackage{robust-externalize}
|
|
17
|
+
\\usepackage{amsmath}
|
|
18
|
+
\\usepackage{multicol}
|
|
19
|
+
\\usepackage{qrcode}
|
|
20
|
+
\\usepackage{listings}
|
|
21
|
+
\\usepackage{hyperref}
|
|
22
|
+
\\usepackage{tikz}
|
|
23
|
+
\\usepackage{amssymb}
|
|
24
|
+
\\usepackage{fancyhdr}
|
|
25
|
+
|
|
26
|
+
\\newenvironment{tightcenter}{%
|
|
27
|
+
\\setlength\\topsep{0pt}
|
|
28
|
+
\\setlength\\parskip{0pt}
|
|
29
|
+
\\begin{center}
|
|
30
|
+
}{%
|
|
31
|
+
\\end{center}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
\\pagestyle{fancy}
|
|
35
|
+
|
|
36
|
+
\\definecolor{codegreen}{rgb}{0,0.6,0}
|
|
37
|
+
\\definecolor{codegray}{rgb}{0.5,0.5,0.5}
|
|
38
|
+
\\definecolor{codepurple}{rgb}{0.58,0,0.82}
|
|
39
|
+
\\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
|
|
40
|
+
|
|
41
|
+
\\lstdefinestyle{mystyle}{
|
|
42
|
+
backgroundcolor=\\color{backcolour},
|
|
43
|
+
commentstyle=\\color{codegreen},
|
|
44
|
+
keywordstyle=\\color{magenta},
|
|
45
|
+
numberstyle=\\tiny\\color{codegray},
|
|
46
|
+
stringstyle=\\color{codepurple},
|
|
47
|
+
basicstyle=\\footnotesize,
|
|
48
|
+
breakatwhitespace=false,
|
|
49
|
+
breaklines=true,
|
|
50
|
+
captionpos=b,
|
|
51
|
+
keepspaces=true,
|
|
52
|
+
numbers=left,
|
|
53
|
+
numbersep=5pt,
|
|
54
|
+
showspaces=false,
|
|
55
|
+
showstringspaces=false,
|
|
56
|
+
showtabs=false,
|
|
57
|
+
tabsize=2,
|
|
58
|
+
xleftmargin=2em
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
\\setlength\\parindent{0pt}
|
|
62
|
+
\\setlength{\\columnseprule}{0.5pt}
|
|
63
|
+
\\lstset{style=mystyle}
|
|
64
|
+
|
|
65
|
+
\\newenvironment{correctionColored}{\\par\\color{RoyalBlue}}{\\par}
|
|
66
|
+
|
|
67
|
+
\\begin{document}
|
|
68
|
+
\\lstset{language=Python}
|
|
69
|
+
%\\fancyhead{}
|
|
70
|
+
%\\fancyfoot{}
|
|
71
|
+
\\renewcommand{\\headrulewidth}{0pt}
|
|
72
|
+
\\renewcommand{\\footrulewidth}{0.4pt}
|
|
73
|
+
\\renewcommand{\\footruleskip}{2pt}
|
|
74
|
+
|
|
75
|
+
`;
|
|
76
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"questionTest.d.ts","sourceRoot":"","sources":["../../src/tests/questionTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAIjE,eAAO,MAAM,YAAY,QAAS,QAAQ,YAAY,QAAQ;;;CAkK7D,CAAC"}
|