📘 A/L ICT Math Note Tool – Sinhala + Boolean Logic

🧮 A/L ICT Math & Boolean Note Tool

Type Sinhala or English notes. Use $...$ for inline math, $$...$$ for display math, and logical symbols like $\overline{X}$ for X̅ (X bar).

📊 Live Preview

Your formatted math and Sinhala text will appear here...

`); printWindow.document.close(); printWindow.print(); }// ✅ MULTI-PAGE FIXED PDF EXPORT - Rewritten for multi-page support async function downloadPDF() { try { const preview = document.getElementById('preview'); // 1. Wait for MathJax to render completely if (window.MathJax && MathJax.typesetPromise) { await MathJax.typesetPromise([preview]); // Give a little extra time for the DOM to settle after MathJax await new Promise(resolve => setTimeout(resolve, 500)); }const { jsPDF } = window.jspdf; // Create a clean container for PDF export const pdfContainer = document.createElement('div'); // Set fixed width for predictable rendering (A4 is 210mm wide) pdfContainer.style.width = '210mm'; pdfContainer.style.padding = '20mm'; // Simulates 20mm margin (10mm top/bottom/left/right) pdfContainer.style.background = 'white'; pdfContainer.style.fontFamily = '"Nirmala UI", "Iskoola Pota", Arial, sans-serif'; pdfContainer.style.fontSize = '12pt'; pdfContainer.style.lineHeight = '1.6'; pdfContainer.style.position = 'absolute'; pdfContainer.style.left = '-9999px'; pdfContainer.style.top = '0'; // Get and clean content let content = tinyMCEEditor.getContent(); content = content .replace(/\\overline\{X\}/g, 'X̅') .replace(/\\overline\{A\}/g, 'A̅') .replace(/\\overline\{B\}/g, 'B̅') .replace(/\\overline\{([^}]*)\}/g, '($1̅)') // Use parentheses for clarity in complex expressions .replace(/\\cdot/g, '·') .replace(/\$\$\\overline\{([^}]*)\}\$\$/g, '$1̅') .replace(/\$\\overline\{([^}]*)\}\$/g, '$1̅') .replace(/\$\$(.*?)\$\$/g, '$1') // Remove display math delimiters .replace(/\$(.*?)\$/g, '$1') // Remove inline math delimiters .replace(/📗|🧩|🧮|📘|📏|📊|🔄|🧹|➕|📄|🧾|📋|🔌|📚|💾|📂|🖨️/g, '') // Remove emojis .replace(//g, '
') .replace(/
/g, '') .replace(//g, '');pdfContainer.innerHTML = `

Student Math Notes

Generated on ${new Date().toLocaleDateString()}

${content}
`; document.body.appendChild(pdfContainer);// 2. Render the content to a single, long canvas const canvas = await html2canvas(pdfContainer, { scale: 2, // Higher scale for better resolution useCORS: true, logging: false, backgroundColor: '#ffffff', // Explicitly set width/height based on the container width: pdfContainer.scrollWidth, height: pdfContainer.scrollHeight });const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF('p', 'mm', 'a4'); const pdfWidth = pdf.internal.pageSize.getWidth(); // 210 mm const pdfHeight = pdf.internal.pageSize.getHeight(); // 297 mm const margin = 10; // 10mm margin on all sides const contentWidth = pdfWidth - (2 * margin); // 190 mm const contentHeight = pdfHeight - (2 * margin); // 277 mm (A4 printable area) // Calculate scaled image dimensions const imgWidth = contentWidth; const imgHeight = (canvas.height * imgWidth) / canvas.width; let heightLeft = imgHeight; // Total height of the image to be printed let position = 0; // Vertical position on the canvas image let pageNum = 1;// 3. Loop through and add pages while (heightLeft > 0) { if (pageNum > 1) { pdf.addPage(); } // Add a cropped part of the long canvas image // The image is added at the top margin (margin) // The y position is negative because we are shifting the image up to show the next part // 1.05 is a slight scaling factor adjustment to prevent small gaps/cutoffs between pages. pdf.addImage(imgData, 'PNG', margin, margin - position, imgWidth * 1.05, imgHeight * 1.05); heightLeft -= contentHeight; position += contentHeight; pageNum++; } // 4. Clean up document.body.removeChild(pdfContainer); // 5. Save PDF pdf.save('Student_Math_Note.pdf'); } catch (error) { console.error('PDF generation error:', error); alert('Error generating PDF. Please ensure your notes are not excessively long or complex, and try again.'); } }// ✅ FIXED WORD EXPORT - Simplified and reliable function downloadWord() { let content = tinyMCEEditor.getContent(); // Convert MathJax to Unicode content = content .replace(/\\overline\{X\}/g, 'X̅') .replace(/\\overline\{A\}/g, 'A̅') .replace(/\\overline\{B\}/g, 'B̅') .replace(/\\overline\{([^}]*)\}/g, '$1̅') .replace(/\\cdot/g, '·') .replace(/\$\$\\overline\{([^}]*)\}\$\$/g, '$1̅') .replace(/\$\\overline\{([^}]*)\}\$/g, '$1̅') .replace(/\$\$(.*?)\$\$/g, '$1') .replace(/\$(.*?)\$/g, '$1') .replace(/📗|🧩|🧮|📘|📏|📊|🔄|🧹|➕|📄|🧾|📋|🔌|📚|💾|📂|🖨️/g, '') .replace(//g, '
') .replace(/
/g, '') .replace(//g, '');const htmlContent = `Student Math Notes

Student Math Notes

${content}
`;const blob = new Blob([htmlContent], { type: 'application/msword' }); const link = document.createElement('a'); const url = URL.createObjectURL(blob); link.href = url; link.download = 'Student_Math_Note.doc'; document.body.appendChild(link); link.click(); setTimeout(() => { document.body.removeChild(link); URL.revokeObjectURL(url); }, 100); }// Copy function function copyConvertedText() { const tempDiv = document.createElement('div'); tempDiv.innerHTML = tinyMCEEditor.getContent(); const plainText = tempDiv.textContent || tempDiv.innerText || ''; navigator.clipboard.writeText(plainText) .then(() => alert("📝 Text copied to clipboard!")) .catch((err) => { console.error('Copy failed:', err); const textArea = document.createElement('textarea'); textArea.value = plainText; document.body.appendChild(textArea); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); alert("📝 Text copied to clipboard!"); }); }// Close modals when clicking outside window.onclick = function(event) { const booleanModal = document.getElementById('booleanModal'); const templatesModal = document.getElementById('templatesModal'); if (event.target == booleanModal) booleanModal.style.display = 'none'; if (event.target == templatesModal) templatesModal.style.display = 'none'; }
Scroll to Top