2020-05-27 16:54:57 +02:00
|
|
|
/**
|
|
|
|
* Turns an array of kanji into a tabular for a chapter overview
|
|
|
|
* @param {string[]} kanjiArray A list of kanji to put into the table
|
|
|
|
* @returns {string} A tex tabular.
|
|
|
|
*/
|
2020-05-24 23:10:30 +02:00
|
|
|
function kanjiTable(kanjiArray) {
|
2020-05-27 16:54:57 +02:00
|
|
|
const xLength = 16;
|
2020-05-24 23:10:30 +02:00
|
|
|
const yLength = Math.ceil(kanjiArray.length/xLength);
|
|
|
|
const sideLength = Math.ceil(Math.sqrt(kanjiArray.length));
|
|
|
|
|
|
|
|
let tableString = '';
|
2020-05-28 22:03:03 +02:00
|
|
|
|
|
|
|
let numberRow = [...Array(xLength).keys()];
|
|
|
|
numberRow = numberRow.map((number) => (number + 1).toString());
|
|
|
|
numberRow = numberRow.map((number) => `{\\large ${number}}`);
|
|
|
|
numberRow = [' ', ...numberRow];
|
|
|
|
tableString += `${numberRow.join(' & ')} \\\\\n\\hline\n\\endhead\n`;
|
|
|
|
|
2020-05-24 23:10:30 +02:00
|
|
|
for (let y_index = 0; y_index < yLength; y_index++) {
|
|
|
|
|
|
|
|
const lineArray = new Array;
|
|
|
|
|
2020-05-28 22:03:03 +02:00
|
|
|
lineArray.push(`{\\large ${y_index*xLength}}`);
|
2020-05-27 16:54:57 +02:00
|
|
|
|
2020-05-24 23:10:30 +02:00
|
|
|
for (let x_index = 0; x_index < xLength; x_index++) {
|
2020-05-25 22:16:04 +02:00
|
|
|
const indexNumber = y_index * xLength + x_index;
|
2020-05-24 23:10:30 +02:00
|
|
|
lineArray.push(kanjiArray[indexNumber] ? kanjiArray[indexNumber] : '');
|
|
|
|
}
|
|
|
|
|
2020-05-28 22:03:03 +02:00
|
|
|
tableString += `${lineArray.join(' & ')} \\\\\n`;
|
2020-05-24 23:10:30 +02:00
|
|
|
}
|
|
|
|
|
2020-05-28 22:03:03 +02:00
|
|
|
return `\\begin{kanjiTable}{ ${'l | ' + 'l '.repeat(xLength)}}
|
|
|
|
${tableString}\\end{kanjiTable}`
|
2020-05-24 23:10:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.kanjiTable = kanjiTable;
|