Repository: satvik314/educhain (language: python)

Issue:
Refactored Readme added Dynamic educhain svg



Discussion / hints:

Fix patch:
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..a894e29
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,1 @@
+*.ipynb linguist-detectable=false
diff --git a/Experiments/experiments.md b/Experiments/experiments.md
new file mode 100644
index 0000000..1650b2b
--- /dev/null
+++ b/Experiments/experiments.md
@@ -0,0 +1,39 @@
+# Experiments
+
+This file records all the experiments and features added to the project.
+
+## Experiment 1: Generate CBSE Question Paper (maths) (Date: 18-8-2024)
+
+* Description: Initial setup of the project to generate CBSE question papers on the fly.
+* Features:
+        + Added functionality to generate question papers for Mathematics subject.
+        + Implemented support for Class XII.
+        + Used the ```pylatexenc``` to handle latex.
+  
+
+
+
+
+
+
+
+## Experiment 2: Addition of Science Subject (Date: YYYY-MM-DD)
+
+* Description: Added support for Science subject in the question paper generator.
+* Features:
+        + Implemented question paper generation for Science subject.
+        + Added support for Class X.
+
+## Experiment 3: Integration with Latex (Date: YYYY-MM-DD)
+
+* Description: Integrated Latex support to render mathematical equations in the question paper.
+* Features:
+        + Added Latex rendering for mathematical equations.
+        + Improved formatting of question papers.
+
+## Experiment 4: Markdown Support (Date: YYYY-MM-DD)
+
+* Description: Added support for Markdown formatting in the question paper generator.
+* Features:
+        + Implemented Markdown rendering for question papers.
+        + Improved readability of question papers.
diff --git a/README.md b/README.md
index aa8e94e..206a0b8 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,19 @@
-# Educhain 🎓🔗
+<p align="center">
+  <img src="https://github.com/VedantDeshmukh2/educhain/blob/main/images/educhain.svg" alt="Educhain Logo" width="800" height="400">
+</p>
+
 
-[![PyPI version](https://badge.fury.io/py/educhain.svg)](https://badge.fury.io/py/educhain)
-[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
-[![Python Versions](https://img.shields.io/pypi/pyversions/educhain.svg)](https://pypi.org/project/educhain/)
-[![Downloads](https://pepy.tech/badge/educhain)](https://pepy.tech/project/educhain)
+<div align="center">
+  
+  [![PyPI version](https://badge.fury.io/py/educhain.svg)](https://badge.fury.io/py/educhain)
+  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
+  [![Python Versions](https://img.shields.io/pypi/pyversions/educhain.svg)](https://pypi.org/project/educhain/)
+  [![Downloads](https://pepy.tech/badge/educhain)](https://pepy.tech/project/educhain)
 
-[Website](https://educhain.in) | [Documentation](docs/index.md) | 
+</div>
+
+# Educhain 🎓🔗
+[Website](https://educhain.in) | [Documentation](docs/index.md) 
 
 Educhain is a powerful Python package that leverages Generative AI to create engaging and personalized educational content. From generating multiple-choice questions to crafting comprehensive lesson plans, Educhain makes it easy to apply AI in various educational scenarios.
 
diff --git a/images/educhain.svg b/images/educhain.svg
new file mode 100644
index 0000000..631a6c2
--- /dev/null
+++ b/images/educhain.svg
@@ -0,0 +1,53 @@
+<svg viewBox="0 0 800 300" xmlns="http://www.w3.org/2000/svg">
+  <style>
+    .title-text {
+      font-size: 48px;
+      font-weight: bold;
+      fill: #3f51b5;
+      animation: title-fade 3s ease-in-out infinite;
+    }
+
+    .subtitle-text {
+      font-size: 28px;
+      fill: #666;
+      animation: subtitle-fade 3s ease-in-out infinite;
+    }
+
+    .divider {
+      stroke: #3f51b5;
+      stroke-width: 4;
+      stroke-linecap: round;
+      animation: divider-dash 3s ease-in-out infinite;
+    }
+
+    .background {
+      fill: linear-gradient(to right, #f5f5f5, #e3f2fd);
+      rx: 20;
+      ry: 20;
+    }
+
+    @keyframes title-fade {
+      0%, 100% { opacity: 1; }
+      50% { opacity: 0.7; }
+    }
+
+    @keyframes subtitle-fade {
+      0%, 100% { opacity: 1; }
+      50% { opacity: 0.7; }
+    }
+
+    @keyframes divider-dash {
+      0% { stroke-dasharray: 0, 800; stroke-dashoffset: 0; }
+      50% { stroke-dasharray: 800, 0; stroke-dashoffset: -400; }
+      100% { stroke-dasharray: 0, 800; stroke-dashoffset: -800; }
+    }
+  </style>
+
+  <rect x="0" y="0" width="800" height="300" class="background" />
+
+  <g transform="translate(100, 100)">
+    <text class="title-text" x="0" y="0">educhain</text>
+    <text class="subtitle-text" x="0" y="60">Revolutionizing education through AI</text>
+    <line class="divider" x1="0" y1="100" x2="600" y2="100" />
+  </g>
+</svg>


Test patch:
diff --git a/Experiments/generate_question_paper_testing.docx b/Experiments/generate_question_paper_testing.docx
new file mode 100644
index 0000000..27859f1
Binary files /dev/null and b/Experiments/generate_question_paper_testing.docx differ
diff --git a/Experiments/generate_question_paper_testing.ipynb b/Experiments/generate_question_paper_testing.ipynb
new file mode 100644
index 0000000..a70da08
--- /dev/null
+++ b/Experiments/generate_question_paper_testing.ipynb
@@ -0,0 +1,683 @@
+{
+  "nbformat": 4,
+  "nbformat_minor": 0,
+  "metadata": {
+    "colab": {
+      "provenance": []
+    },
+    "kernelspec": {
+      "name": "python3",
+      "display_name": "Python 3"
+    },
+    "language_info": {
+      "name": "python"
+    }
+  },
+  "cells": [
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# This notebook aims to create a function to prepare a CBSE question paper on the fly --> educhain\n",
+        "\n",
+        "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1nwpjaV14HJLwrM8U-Xy1RrTCJ6yvKJOT?usp=sharing)"
+      ],
+      "metadata": {
+        "id": "Iz4Kuo0e5jfn"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## Installing Libraries"
+      ],
+      "metadata": {
+        "id": "XOnR9ojD5ycO"
+      }
+    },
+    {
+      "cell_type": "code",
+      "execution_count": 1,
+      "metadata": {
+        "colab": {
+          "base_uri": "https://localhost:8080/"
+        },
+        "id": "7HgsN43E5f_3",
+        "outputId": "088ad216-d93f-4522-e00d-39999ff96988"
+      },
+      "outputs": [
+        {
+          "output_type": "stream",
+          "name": "stdout",
+          "text": [
+            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.4/50.4 kB\u001b[0m \u001b[31m678.9 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m244.3/244.3 kB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m997.8/997.8 kB\u001b[0m \u001b[31m12.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.3/2.3 MB\u001b[0m \u001b[31m29.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m362.5/362.5 kB\u001b[0m \u001b[31m17.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.9/318.9 kB\u001b[0m \u001b[31m14.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m391.5/391.5 kB\u001b[0m \u001b[31m14.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m140.4/140.4 kB\u001b[0m \u001b[31m7.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.2/49.2 kB\u001b[0m \u001b[31m1.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.9/141.9 kB\u001b[0m \u001b[31m5.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[?25h"
+          ]
+        }
+      ],
+      "source": [
+        "!pip install python-docx langchain langchain-community openai --quiet\n"
+      ]
+    },
+    {
+      "cell_type": "markdown",
+      "source": [],
+      "metadata": {
+        "id": "5UI9x2hN50ln"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## Installing Libraries"
+      ],
+      "metadata": {
+        "id": "eHZG8-u16Gn5"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "import os\n",
+        "from langchain.chat_models import ChatOpenAI\n",
+        "from langchain.prompts import ChatPromptTemplate\n",
+        "from langchain.chains import LLMChain\n",
+        "from pydantic import BaseModel, Field\n",
+        "from typing import List, Union,Optional\n",
+        "from docx import Document\n",
+        "from docx.shared import Pt\n",
+        "from docx.oxml.ns import qn\n",
+        "from docx.enum.text import WD_PARAGRAPH_ALIGNMENT\n",
+        "from google.colab import userdata\n",
+        "\n",
+        "# Set your OpenAI API key\n",
+        "openai_api_key = userdata.get(\"OPENAI_API_KEY\")\n",
+        "# Set up the OpenAI API key\n",
+        "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"
+      ],
+      "metadata": {
+        "id": "Tc3gewN-5_89"
+      },
+      "execution_count": 3,
+      "outputs": []
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "## Models.py"
+      ],
+      "metadata": {
+        "id": "vjPPLfJc6Evz"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "class MCQQuestion(BaseModel):\n",
+        "    question: str\n",
+        "    options: List[str]\n",
+        "    correct_answer: str\n",
+        "\n",
+        "class AssertionReasonQuestion(BaseModel):\n",
+        "    assertion: str\n",
+        "    reason: str\n",
+        "    correct_answer: str\n",
+        "\n",
+        "class ShortAnswerQuestion(BaseModel):\n",
+        "    question: str\n",
+        "    max_marks: int\n",
+        "\n",
+        "class LongAnswerQuestion(BaseModel):\n",
+        "    question: str\n",
+        "    max_marks: int\n",
+        "\n",
+        "class SourceBasedQuestion(BaseModel):\n",
+        "    source_text: str\n",
+        "    questions: List[ShortAnswerQuestion]\n",
+        "\n",
+        "# Pydantic model for the entire question paper\n",
+        "class QuestionPaper(BaseModel):\n",
+        "    section_a: List[Union[MCQQuestion, AssertionReasonQuestion]] = Field(..., min_items=20, max_items=20)\n",
+        "    section_b: List[ShortAnswerQuestion] = Field(..., min_items=5, max_items=5)\n",
+        "    section_c: List[ShortAnswerQuestion] = Field(..., min_items=6, max_items=6)\n",
+        "    section_d: List[LongAnswerQuestion] = Field(..., min_items=4, max_items=4)\n",
+        "    section_e: List[SourceBasedQuestion] = Field(..., min_items=3, max_items=3)"
+      ],
+      "metadata": {
+        "id": "KDkiajAK5_TZ"
+      },
+      "execution_count": 4,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "from docx import Document\n",
+        "from docx.shared import Pt\n",
+        "from docx.enum.text import WD_PARAGRAPH_ALIGNMENT\n",
+        "from pylatexenc.latex2text import LatexNodes2Text\n",
+        "from pylatexenc.latex2text import LatexNodes2Text\n",
+        "\n",
+        "latex_converter = LatexNodes2Text()\n",
+        "\n",
+        "# Initialize the ChatOpenAI model\n",
+        "chat = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0.5)\n",
+        "\n",
+        "# Create a prompt template\n",
+        "def create_prompt_template(subject, topic, grade, difficulty=None, custom_instructions=None, highlight_topics=None):\n",
+        "    difficulty_str = f\"The difficulty level should be {difficulty}.\" if difficulty else \"\"\n",
+        "    custom_instructions_str = f\"Custom Instructions: {custom_instructions}\" if custom_instructions else \"\"\n",
+        "    highlight_topics_str = f\"Highlight the following topics in the questions: {highlight_topics}\" if highlight_topics else \"\"\n",
+        "\n",
+        "    prompt_template = ChatPromptTemplate.from_template(\n",
+        "        f\"\"\"Generate a {subject} question paper for Class {grade} with the following structure:\n",
+        "        Section A: 18 MCQs and 2 Assertion-Reason questions (1 mark each)\n",
+        "        Section B: 5 Very Short Answer questions (2 marks each)\n",
+        "        Section C: 6 Short Answer questions (3 marks each)\n",
+        "        Section D: 4 Long Answer questions (5 marks each)\n",
+        "        Section E: 3 source-based/case-based/passage-based questions (4 marks each)\n",
+        "\n",
+        "        Ensure that the questions cover the following topic: {topic}.\n",
+        "        {difficulty_str}\n",
+        "\n",
+        "        {custom_instructions_str}\n",
+        "\n",
+        "        {highlight_topics_str}\n",
+        "\n",
+        "        Format each question as follows:\n",
+        "\n",
+        "        Section A:\n",
+        "        MCQ1: Question text\n",
+        "        A) Option A\n",
+        "        B) Option B\n",
+        "        C) Option C\n",
+        "        D) Option D\n",
+        "        Correct Answer: X\n",
+        "\n",
+        "        AR1: Assertion: Assertion text\n",
+        "        Reason: Reason text\n",
+        "        Correct Answer: True/False\n",
+        "\n",
+        "        Section B:\n",
+        "        B1: Question text (2 marks)\n",
+        "\n",
+        "        Section C:\n",
+        "        C1: Question text (3 marks)\n",
+        "\n",
+        "        Section D:\n",
+        "        D1: Question text (5 marks)\n",
+        "\n",
+        "        Section E:\n",
+        "        E1: Source text\n",
+        "        a) Question 1 (1 mark)\n",
+        "        b) Question 2 (1 mark)\n",
+        "        c) Question 3 (1 mark)\n",
+        "        d) Question 4 (1 mark)\n",
+        "\n",
+        "        Generate the complete question paper following this format.\n",
+        "        \"\"\"\n",
+        "    )\n",
+        "    return prompt_template\n",
+        "# Generate the question paper\n",
+        "def generate_question_paper(subject, topic, grade, difficulty=None, custom_instructions=None, highlight_topics=None):\n",
+        "    # Create a prompt template with user-defined parameters\n",
+        "    prompt_template = create_prompt_template(subject, topic, grade, difficulty, custom_instructions, highlight_topics)\n",
+        "\n",
+        "    # Generate the question paper content using ChatOpenAI\n",
+        "    chain = LLMChain(llm=chat, prompt=prompt_template)\n",
+        "    response = chain.run({})\n",
+        "\n",
+        "    # Format the response into a structured format\n",
+        "    content = response.strip()\n",
+        "    return content\n",
+        "\n",
+        "# Add lines between sections and handle markdown-like syntax\n",
+        "def format_with_lines(content):\n",
+        "    sections = content.split('\\nSection ')\n",
+        "    formatted_content = sections[0]\n",
+        "    for section in sections[1:]:\n",
+        "        formatted_content += '\\n\\n' + '─' * 80 + '\\n\\nSection ' + section\n",
+        "    return formatted_content\n",
+        "\n",
+        "def apply_markdown_formatting(doc, line):\n",
+        "    if line.startswith('# '):\n",
+        "        # Heading 1\n",
+        "        p = doc.add_paragraph(latex_converter.latex_to_text(line[2:]))\n",
+        "        p.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER\n",
+        "        run = p.runs[0]\n",
+        "        run.bold = True\n",
+        "        run.font.size = Pt(16)\n",
+        "    elif line.startswith('## '):\n",
+        "        # Heading 2\n",
+        "        p = doc.add_paragraph(latex_converter.latex_to_text(line[3:]))\n",
+        "        run = p.runs[0]\n",
+        "        run.bold = True\n",
+        "        run.font.size = Pt(14)\n",
+        "    elif line.startswith('### '):\n",
+        "        # Heading 3\n",
+        "        p = doc.add_paragraph(latex_converter.latex_to_text(line[4:]))\n",
+        "        run = p.runs[0]\n",
+        "        run.bold = True\n",
+        "        run.font.size = Pt(12)\n",
+        "    elif '**' in line:\n",
+        "        # Bold text\n",
+        "        parts = line.split('**')\n",
+        "        p = doc.add_paragraph()\n",
+        "        for i, part in enumerate(parts):\n",
+        "            run = p.add_run(latex_converter.latex_to_text(part))\n",
+        "            if i % 2 == 1:\n",
+        "                run.bold = True\n",
+        "    else:\n",
+        "        # Normal text\n",
+        "        doc.add_paragraph(latex_converter.latex_to_text(line))\n",
+        "\n",
+        "# Save the content to a .txt file\n",
+        "def save_to_txt(filename, content):\n",
+        "    with open(filename, \"w\") as f:\n",
+        "        f.write(content)\n",
+        "\n",
+        "# Save the content to a .docx file\n",
+        "def save_to_docx(filename, content):\n",
+        "    doc = Document()\n",
+        "    for line in content.splitlines():\n",
+        "        if line.strip() == \"─\" * 80:\n",
+        "            doc.add_paragraph()\n",
+        "            doc.add_paragraph(\"─\" * 80)\n",
+        "        else:\n",
+        "            apply_markdown_formatting(doc, line)\n",
+        "    doc.save(filename)\n",
+        "\n",
+        "# Generate the question paper based on user input and print it\n",
+        "subject = \"Mathematics\"\n",
+        "topic = \"Calculus\"\n",
+        "grade = \"XII\"\n",
+        "difficulty = \"Medium\"  # Optional\n",
+        "custom_instructions = \"Focus on application-based questions.\"  # Optional\n",
+        "highlight_topics = \"Integration, Differentiation\"  # Optional\n",
+        "\n",
+        "generated_paper = generate_question_paper(subject, topic, grade, difficulty, custom_instructions, highlight_topics)\n",
+        "formatted_paper = format_with_lines(generated_paper)\n",
+        "print(formatted_paper)\n",
+        "\n",
+        "# Save the formatted paper to a .txt file\n",
+        "save_to_txt(\"question_paper.txt\", formatted_paper)\n",
+        "\n",
+        "# Save the formatted paper to a .docx file\n",
+        "save_to_docx(\"question_paper.docx\", formatted_paper)"
+      ],
+      "metadata": {
+        "colab": {
+          "base_uri": "https://localhost:8080/"
+        },
+        "id": "-fExWf0T9AM-",
+        "outputId": "4cf6da4f-a2f5-463a-c580-eefe3b85ec19"
+      },
+      "execution_count": 8,
+      "outputs": [
+        {
+          "output_type": "stream",
+          "name": "stdout",
+          "text": [
+            "# Class XII Mathematics Question Paper: Calculus\n",
+            "\n",
+            "**Instructions:** All questions are compulsory. The question paper consists of 5 sections. \n",
+            "\n",
+            "---\n",
+            "\n",
+            "### Section A: (20 Marks)\n",
+            "\n",
+            "**MCQ1:** What is the derivative of \\( f(x) = x^3 + 3x^2 - 5x + 7 \\)?  \n",
+            "A) \\( 3x^2 + 6x - 5 \\)  \n",
+            "B) \\( 3x^2 + 5 \\)  \n",
+            "C) \\( 3x^2 + 6x + 7 \\)  \n",
+            "D) \\( 3x^3 + 2x \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ2:** Which of the following is the integral of \\( \\sin(x) \\)?  \n",
+            "A) \\( -\\cos(x) + C \\)  \n",
+            "B) \\( \\cos(x) + C \\)  \n",
+            "C) \\( \\sin(x) + C \\)  \n",
+            "D) \\( -\\sin(x) + C \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ3:** If \\( f(x) = e^{2x} \\), what is \\( f'(x) \\)?  \n",
+            "A) \\( 2e^{2x} \\)  \n",
+            "B) \\( e^{2x} \\)  \n",
+            "C) \\( 2xe^{2x} \\)  \n",
+            "D) \\( 2e^{x} \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ4:** The area under the curve \\( y = x^2 \\) from \\( x = 0 \\) to \\( x = 2 \\) is:  \n",
+            "A) \\( \\frac{8}{3} \\)  \n",
+            "B) \\( 2 \\)  \n",
+            "C) \\( 4 \\)  \n",
+            "D) \\( \\frac{4}{3} \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ5:** What is the second derivative of \\( f(x) = 3x^4 - 4x^3 + 2x - 1 \\)?  \n",
+            "A) \\( 36x^2 - 24x + 2 \\)  \n",
+            "B) \\( 12x^2 - 12x + 2 \\)  \n",
+            "C) \\( 12x^3 - 12 \\)  \n",
+            "D) \\( 36x^3 - 24x + 2 \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ6:** The integral \\( \\int (3x^2 + 2x + 1) \\, dx \\) evaluates to:  \n",
+            "A) \\( x^3 + x^2 + x + C \\)  \n",
+            "B) \\( x^3 + x^2 + C \\)  \n",
+            "C) \\( x^3 + x^2 + x + 1 \\)  \n",
+            "D) \\( 3x^3 + x^2 + C \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ7:** If \\( f(x) = \\ln(x^2 + 1) \\), what is \\( f'(1) \\)?  \n",
+            "A) \\( 0 \\)  \n",
+            "B) \\( \\frac{1}{2} \\)  \n",
+            "C) \\( 1 \\)  \n",
+            "D) \\( \\frac{1}{3} \\)  \n",
+            "**Correct Answer:** B\n",
+            "\n",
+            "**MCQ8:** The fundamental theorem of calculus connects which two concepts?  \n",
+            "A) Derivatives and limits  \n",
+            "B) Integration and differentiation  \n",
+            "C) Algebra and geometry  \n",
+            "D) Functions and sequences  \n",
+            "**Correct Answer:** B\n",
+            "\n",
+            "**MCQ9:** The derivative of \\( f(x) = \\tan(x) \\) is:  \n",
+            "A) \\( \\sec^2(x) \\)  \n",
+            "B) \\( \\cos^2(x) \\)  \n",
+            "C) \\( \\sin^2(x) \\)  \n",
+            "D) \\( \\sec(x) \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ10:** The integral \\( \\int_0^1 x^3 \\, dx \\) equals:  \n",
+            "A) \\( \\frac{1}{4} \\)  \n",
+            "B) \\( \\frac{1}{5} \\)  \n",
+            "C) \\( \\frac{1}{3} \\)  \n",
+            "D) \\( \\frac{1}{6} \\)  \n",
+            "**Correct Answer:** B\n",
+            "\n",
+            "**MCQ11:** The derivative of \\( f(x) = \\sqrt{x} \\) is:  \n",
+            "A) \\( \\frac{1}{2\\sqrt{x}} \\)  \n",
+            "B) \\( \\frac{1}{\\sqrt{x}} \\)  \n",
+            "C) \\( \\frac{1}{2}x^{-\\frac{1}{2}} \\)  \n",
+            "D) Both A and C  \n",
+            "**Correct Answer:** D\n",
+            "\n",
+            "**MCQ12:** The integral \\( \\int e^{2x} \\, dx \\) results in:  \n",
+            "A) \\( \\frac{1}{2}e^{2x} + C \\)  \n",
+            "B) \\( 2e^{2x} + C \\)  \n",
+            "C) \\( e^{2x} + C \\)  \n",
+            "D) \\( e^{x^2} + C \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ13:** If \\( f(x) = x^4 - 8x^2 + 16 \\), find \\( f'(2) \\).  \n",
+            "A) \\( 0 \\)  \n",
+            "B) \\( -16 \\)  \n",
+            "C) \\( 16 \\)  \n",
+            "D) \\( 8 \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ14:** The integral \\( \\int_1^3 (3x^2 - 4) \\, dx \\) evaluates to:  \n",
+            "A) \\( 8 \\)  \n",
+            "B) \\( 10 \\)  \n",
+            "C) \\( 6 \\)  \n",
+            "D) \\( 4 \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ15:** If \\( f(x) = 5x^3 + 2x^2 - 3x + 1 \\), what is \\( f''(x) \\)?  \n",
+            "A) \\( 30x + 4 \\)  \n",
+            "B) \\( 15x^2 + 4 \\)  \n",
+            "C) \\( 15x^2 - 3 \\)  \n",
+            "D) \\( 30x^2 + 2 \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ16:** The limit \\( \\lim_{x \\to 0} \\frac{\\sin(x)}{x} \\) is:  \n",
+            "A) \\( 0 \\)  \n",
+            "B) \\( 1 \\)  \n",
+            "C) \\( \\infty \\)  \n",
+            "D) \\( -1 \\)  \n",
+            "**Correct Answer:** B\n",
+            "\n",
+            "**MCQ17:** The derivative of \\( f(x) = \\ln(x) + \\ln(x+1) \\) is:  \n",
+            "A) \\( \\frac{1}{x} + \\frac{1}{x+1} \\)  \n",
+            "B) \\( \\frac{1}{x} - \\frac{1}{x+1} \\)  \n",
+            "C) \\( \\frac{1}{x^2} + \\frac{1}{(x+1)^2} \\)  \n",
+            "D) \\( \\frac{1}{x^2} - \\frac{1}{(x+1)^2} \\)  \n",
+            "**Correct Answer:** A\n",
+            "\n",
+            "**MCQ18:** Which of the following represents the integral \\( \\int_0^1 (2x + 1) \\, dx \\)?  \n",
+            "A) \\( 1 \\)  \n",
+            "B) \\( \\frac{3}{2} \\)  \n",
+            "C) \\( 2 \\)  \n",
+            "D) \\( \\frac{1}{2} \\)  \n",
+            "**Correct Answer:** B\n",
+            "\n",
+            "**Assertion-Reason Questions:**\n",
+            "\n",
+            "**AR1:** Assertion: The derivative of a constant function is zero.  \n",
+            "Reason: A constant function does not change with respect to its variable.  \n",
+            "**Correct Answer:** True\n",
+            "\n",
+            "**AR2:** Assertion: The integral of a function gives its area under the curve.  \n",
+            "Reason: The area under the curve can be negative.  \n",
+            "**Correct Answer:** False\n",
+            "\n",
+            "---\n",
+            "\n",
+            "### Section B: (10 Marks)\n",
+            "\n",
+            "**B1:** Find the value of \\( \\int_0^1 x^2 \\, dx \\). (2 marks)\n",
+            "\n",
+            "**B2:** Differentiate \\( f(x) = \\cos(3x) + 5 \\). (2 marks)\n",
+            "\n",
+            "**B3:** Evaluate \\( \\frac{d}{dx} (x^5 - 3x^3 + 2x) \\). (2 marks)\n",
+            "\n",
+            "**B4:** Find \\( \\int (4x^3 - 2x^2 + 3) \\, dx \\). (2 marks)\n",
+            "\n",
+            "**B5:** What is the derivative of \\( f(x) = \\frac{1}{x} \\)? (2 marks)\n",
+            "\n",
+            "---\n",
+            "\n",
+            "### Section C: (18 Marks)\n",
+            "\n",
+            "**C1:** Evaluate \\( \\int (3x^2 + 2) \\, dx \\) and find the constant of integration if \\( f(0) = 1 \\). (3 marks)\n",
+            "\n",
+            "**C2:** If \\( f(x) = x^2 \\sin(x) \\), find \\( f'(x) \\) using the product rule. (3 marks)\n",
+            "\n",
+            "**C3:** Prove that \\( \\frac{d}{dx} (e^{ax}) = ae^{ax} \\) for any constant \\( a \\). (3 marks)\n",
+            "\n",
+            "**C4:** Calculate the area under the curve \\( y = x^2 \\) from \\( x = 1 \\) to \\( x = 3 \\). (3 marks)\n",
+            "\n",
+            "**C5:** Find the maximum value of \\( f(x) = -x^2 + 4x \\) using differentiation. (3 marks)\n",
+            "\n",
+            "**C6:** Evaluate \\( \\int_1^2 (6x - 4) \\, dx \\). (3 marks)\n",
+            "\n",
+            "---\n",
+            "\n",
+            "### Section D: (20 Marks)\n",
+            "\n",
+            "**D1:** Find the value of \\( \\int (2x^3 - 3x^2 + 4x - 5) \\, dx \\) and evaluate it from \\( x = 1 \\) to \\( x = 3 \\). (5 marks)\n",
+            "\n",
+            "**D2:** Prove that if \\( f(x) = x^2 \\cos(x) \\), then \\( f'(x) = 2x \\cos(x) - x^2 \\sin(x) \\). (5 marks)\n",
+            "\n",
+            "**D3:** Using the first principle of derivatives, find \\( f'(x) \\) for \\( f(x) = x^2 + 5x \\). (5 marks)\n",
+            "\n",
+            "**D4:** Evaluate \\( \\int_0^1 (2x^2 - 3x + 1) \\, dx \\) and interpret the result geometrically. (5 marks)\n",
+            "\n",
+            "---\n",
+            "\n",
+            "### Section E: (12 Marks)\n",
+            "\n",
+            "**E1:** Consider the function \\( f(x) = x^3 - 3x + 1 \\).  \n",
+            "a) Find \\( f'(x) \\). (1 mark)  \n",
+            "b) Determine the critical points of \\( f(x) \\). (1 mark)  \n",
+            "c) Find the intervals of increase and decrease. (1 mark)  \n",
+            "d) What are the local maxima and minima? (1 mark)  \n",
+            "\n",
+            "**E2:** A company’s profit \\( P(x) \\) in thousands of dollars is given by \\( P(x) = -2x^2 + 12x - 10 \\), where \\( x \\) is the number of units sold in thousands.  \n",
+            "a) Find \\( P'(x) \\). (1 mark)  \n",
+            "b) Determine the number of units that maximizes the profit. (1 mark)  \n",
+            "c) Calculate the maximum profit. (1 mark)  \n",
+            "d) What is the profit when 2 units are sold? (1 mark)  \n",
+            "\n",
+            "**E3:** The velocity of a particle is given by \\( v(t) = 6t - 4 \\) m/s.  \n",
+            "a) Find the acceleration of the particle. (1 mark)  \n",
+            "b) Determine the time when the particle comes to rest. (1 mark)  \n",
+            "c) Calculate the displacement of the particle from \\( t = 0 \\) to \\( t = 2 \\). (1 mark)  \n",
+            "d) What is the total distance traveled during this time? (1 mark)  \n",
+            "\n",
+            "---\n",
+            "\n",
+            "**End of Question Paper**\n"
+          ]
+        }
+      ]
+    },
+    {
+      "cell_type": "markdown",
+      "source": [],
+      "metadata": {
+        "id": "w5tjEQKp8aTc"
+      }
+    },
+    {
+      "cell_type": "markdown",
+      "source": [
+        "# pylatexenc testing"
+      ],
+      "metadata": {
+        "id": "SyLG8UOe9s0w"
+      }
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "!pip install pylatexenc --quiet"
+      ],
+      "metadata": {
+        "colab": {
+          "base_uri": "https://localhost:8080/"
+        },
+        "id": "K9zKy7UK8b-4",
+        "outputId": "8cb0f595-1232-4b30-b58e-3fbe98ca0d80"
+      },
+      "execution_count": 6,
+      "outputs": [
+        {
+          "output_type": "stream",
+          "name": "stdout",
+          "text": [
+            "\u001b[?25l     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/162.6 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m30.7/162.6 kB\u001b[0m \u001b[31m620.7 kB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.0/162.6 kB\u001b[0m \u001b[31m793.4 kB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━\u001b[0m \u001b[32m143.4/162.6 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m162.6/162.6 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
+            "  Building wheel for pylatexenc (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
+          ]
+        }
+      ]
+    },
+    {
+      "cell_type": "code",
+      "source": [
+        "from docx import Document\n",
+        "from docx.shared import Pt\n",
+        "from docx.enum.text import WD_PARAGRAPH_ALIGNMENT\n",
+        "from pylatexenc.latex2text import LatexNodes2Text\n",
+        "from pylatexenc.latex2text import LatexNodes2Text\n",
+        "\n",
+        "latex_converter = LatexNodes2Text()\n",
+        "\n",
+        "def apply_markdown_formatting(doc, line):\n",
+        "    if line.startswith('# '):\n",
+        "        # Heading 1\n",
+        "        p = doc.add_paragraph(latex_converter.latex_to_text(line[2:]))\n",
+        "        p.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER\n",
+        "        run = p.runs[0]\n",
+        "        run.bold = True\n",
+        "        run.font.size = Pt(16)\n",
+        "    elif line.startswith('## '):\n",
+        "        # Heading 2\n",
+        "        p = doc.add_paragraph(latex_converter.latex_to_text(line[3:]))\n",
+        "        run = p.runs[0]\n",
+        "        run.bold = True\n",
+        "        run.font.size = Pt(14)\n",
+        "    elif line.startswith('### '):\n",
+        "        # Heading 3\n",
+        "        p = doc.add_paragraph(latex_converter.latex_to_text(line[4:]))\n",
+        "        run = p.runs[0]\n",
+        "        run.bold = True\n",
+        "        run.font.size = Pt(12)\n",
+        "    elif '**' in line:\n",
+        "        # Bold text\n",
+        "        parts = line.split('**')\n",
+        "        p = doc.add_paragraph()\n",
+        "        for i, part in enumerate(parts):\n",
+        "            run = p.add_run(latex_converter.latex_to_text(part))\n",
+        "            if i % 2 == 1:\n",
+        "                run.bold = True\n",
+        "    else:\n",
+        "        # Normal text\n",
+        "        doc.add_paragraph(latex_converter.latex_to_text(line))\n",
+        "\n",
+        "doc = Document()\n",
+        "\n",
+        "# Sample text (a portion of what you provided)\n",
+        "sample_text = \"\"\"\n",
+        "### Mathematics Question Paper - Class XII\n",
+        "\n",
+        "#### Section A:\n",
+        "**MCQ1:** If \\( f(x) = x^3 - 3x^2 + 5 \\), then \\( f'(2) \\) is:\n",
+        "A) 1\n",
+        "B) 2\n",
+        "C) 5\n",
+        "D) 7\n",
+        "Correct Answer: D\n",
+        "\n",
+        "**MCQ2:** The integral of \\( \\int e^{2x} \\, dx \\) is:\n",
+        "A) \\( \\frac{1}{2} e^{2x} + C \\)\n",
+        "B) \\( 2e^{2x} + C \\)\n",
+        "C) \\( e^{2x} + C \\)\n",
+        "D) \\( \\frac{1}{2} e^{x} + C \\)\n",
+        "Correct Answer: A\n",
+        "\n",
+        "**MCQ3:** The derivative of \\( \\sin(x^2) \\) with respect to \\( x \\) is:\n",
+        "A) \\( \\cos(x^2) \\)\n",
+        "B) \\( 2x \\cos(x^2) \\)\n",
+        "C) \\( -2x \\cos(x^2) \\)\n",
+        "D) \\( 2x \\sin(x^2) \\)\n",
+        "Correct Answer: B\n",
+        "\"\"\"\n",
+        "\n",
+        "# Apply formatting to each line\n",
+        "for line in sample_text.split('\\n'):\n",
+        "    apply_markdown_formatting(doc, line)\n",
+        "\n",
+        "# Save the document\n",
+        "doc.save('formatted_math_paper.docx')"
+      ],
+      "metadata": {
+        "id": "XjV-9dKB7VY_"
+      },
+      "execution_count": 7,
+      "outputs": []
+    },
+    {
+      "cell_type": "code",
+      "source": [],
+      "metadata": {
+        "id": "JpAQU6YU8tnm"
+      },
+      "execution_count": null,
+      "outputs": []
+    }
+  ]
+}