# -*- coding: utf-8 -*-
"""Round 250: batch add 5 Mathematics PhD (third batch of basic-science PhD sweep)
- NYU Courant Mathematics PhD (Dec 18 strong rec / Jan 4 final; GRE General+Subject optional; ETS 2596; 72 credits by Year 4; Written Comprehensive grade A; Oral Preliminary)
- Brown Mathematics PhD (pure math, NOT Applied Math division; Jan 1, 2027; GRE General not required; Subject entirely optional; 30-40 students; ~15 offers from 400+ apps; Fall 2027 new short-video upload requirement)
- UMich Mathematics PhD (Dec 15, 2026; GRE General not required per Rackham policy; Subject strictly optional; ETS 1839; two tracks Mathematics and AIM; 83% grad students in PhD; all PhD fully funded)
- UCLA Mathematics PhD (Dec 13, 2026; GRE Math Subject required per grad.ucla.edu 2027-2028 catalog; PhD only - MA/MAT suspended; 3.5 GPA upper-division math; 12 quarter upper-division math courses)
- Duke Mathematics PhD (Dec 15, 2026 11:59:59pm EST; GRE General+Subject both optional; TOEFL 90 / IELTS 7.0 / Duolingo 125; 3 LOR + SOP + Resume; 100% financial aid; Fall only)
Key finding: Math PhD GRE policy continues to diverge. This batch leans GRE-free: NYU, Brown, UMich, Duke all General-optional; UCLA still requires Math Subject.
"""
import os, re

BASE = os.path.dirname(os.path.abspath(__file__))
DET = os.path.join(BASE, "details")
os.makedirs(DET, exist_ok=True)

PROGRAMS = [
    {
        "id": "nyu-math-phd",
        "s": "nyu",
        "n": "数学博士（Courant）",
        "en": "PhD in Mathematics (New York University, Graduate School of Arts and Science, Courant Institute of Mathematical Sciences; 72 credits by end of Year 4; Written Comprehensive Examination with grade A; Oral Preliminary Examination; Oral Defense of Dissertation; located in Greenwich Village, NYC; access to NYU-ECNU Institute of Mathematical Sciences and NYU Shanghai)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5 years; 72 credits by end of Year 4; Written Comprehensive Exam (grade A); Oral Preliminary Exam; Dissertation; on-campus residential (New York, NY); Fall admission only",
        "ddl": "Fall 2027: application is open. **Strongly recommended deadline December 18, 2026, 5:00 p.m. ET; final deadline January 4, 2027, 5:00 p.m. ET**. If a deadline falls on a weekend or US federal holiday, the next business day applies. No rolling admissions.",
        "lang": "TOEFL iBT minimum 100 (recommended; sub-600 paper / 250 computer not recommended) or IELTS Academic minimum overall 7.0 required for non-native English speakers; waiver for accredited degree from English-instructed institution",
        "test": {"cls": "GRE GENERAL AND SUBJECT BOTH OPTIONAL (NYU GSAS Mathematics: 'PhD in Mathematics: optional.' The department views GRE scores - both General and Mathematics Subject Test - as useful information; however, applications without these scores will not be at a disadvantage: more weight is placed on other elements. ETS school code 2596 (NYU Grad Arts Sci); dept code 0703 Math; TOEFL dept code 72. 3 LOR (at least 2 from math/science faculty); CV; SOP; transcripts.)"},
        "tui": "NYU GSAS typically offers multi-year fully-funded support to admitted PhD students, including tuition scholarship and stipend through a combination of Graduate Assistantships, Teaching Fellowships, and research grants. GSAS requires students to maintain GPA of 3.0 or higher and complete at least two thirds of attempted credits.",
        "url": "details/nyu-math-phd.html",
    },
    {
        "id": "brown-math-phd",
        "s": "brown",
        "n": "数学博士",
        "en": "PhD in Mathematics (Brown University, Graduate School, Department of Mathematics - pure mathematics division; NOT the separate Division of Applied Mathematics which has its own PhD program; core courses in differentiable manifolds, real functions, complex functions, algebra, and topology; small enrollment of 30-40 students; located in Providence, RI)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5 years; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Providence, RI); Fall admission only",
        "ddl": "Fall 2027: application opens September 8, 2026. **Deadline January 1, 2027, 11:59 p.m. ET** (Brown Graduate School program explorer). New feature for Fall 2027: applicant uploads a short video in addition to written materials.",
        "lang": "TOEFL iBT / IELTS Academic required for applicants from non-English-speaking countries; exemption for applicants who have completed one or more years of study in an English-speaking country",
        "test": {"cls": "GRE GENERAL NOT REQUIRED, MATH SUBJECT ENTIRELY OPTIONAL (Brown Mathematics: 'Brown no longer requires the General GRE. The mathematics Subject GRE is entirely optional.' ETS code 3094. Note: Brown Applied Mathematics Division is a SEPARATE PhD program (Dec 9, 2026; General required; Subject highly recommended) - this entry is for pure Mathematics, NOT Applied Math.)"},
        "tui": "Brown Graduate School typically offers multi-year fully-funded support to admitted Mathematics PhD students, including full tuition, stipend, and health insurance through Teaching Assistantships, Research Assistantships, and fellowship awards. Small cohort (30-40 students) enables close faculty contact.",
        "url": "details/brown-math-phd.html",
    },
    {
        "id": "umich-math-phd",
        "s": "umich",
        "n": "数学博士",
        "en": "PhD in Mathematics (University of Michigan, Rackham Graduate School, College of Literature, Science, and the Arts, Department of Mathematics; two PhD tracks: Mathematics and Applied & Interdisciplinary Mathematics (AIM); 155 graduate students, ~83% in PhD; all PhD students fully funded through GSI/GSR/fellowship; located in Ann Arbor, MI)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5 years; Fall semester admission only; Qualifying Review; Preliminary Examination by start of Year 4; Candidacy by end of Year 3; dissertation; on-campus residential (Ann Arbor, MI)",
        "ddl": "Fall 2027: application opens September 2026. **Deadline December 15, 2026** for PhD (MS deadline February 1, 2027). Applications only accepted for Fall term (no Winter/Spring/Summer). All decisions no later than April 15, 2027.",
        "lang": "TOEFL iBT / IELTS Academic required for students whose native language is not English; scores must be no older than two years as of Admission Deadline; minimum scores per Rackham Graduate School rules; TOEFL iBT Special Home Edition and IELTS Indicator accepted; exemptions per Rackham rules",
        "test": {"cls": "GRE GENERAL NOT REQUIRED, MATH SUBJECT STRICTLY OPTIONAL (UMich Mathematics: 'GRE General Test scores are no longer included in the admission process in accordance with a policy of the Rackham Graduate School. GRE Mathematics Subject Test scores are strictly optional; however, if an applicant chooses so, they may submit them as a combined PDF file with their transcript or personal statement.' ETS Rackham code 1839.)"},
        "tui": "All admitted PhD students in the UMich Mathematics Department receive full support through a combination of Graduate Student Instructorships (GSI), Graduate Student Research Assistantships (GSR), and fellowships. The MS program is completely self-funded; GSI positions are reserved for PhD students.",
        "url": "details/umich-math-phd.html",
    },
    {
        "id": "ucla-math-phd",
        "s": "ucla",
        "n": "数学博士",
        "en": "PhD in Mathematics (University of California Los Angeles, Graduate Division, Department of Mathematics; PhD only - MA and MAT programs suspended indefinitely; minimum 3.5 GPA in upper-division mathematics courses; 12 quarter (or 8 semester) upper-division math courses required; located in Los Angeles, CA)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Los Angeles, CA); Fall quarter admission only",
        "ddl": "Fall 2027: application opens in September 2026. **Deadline December 13, 2026** (department page; grad.ucla.edu catalog also lists December 15 as program deadline). Application review begins late December; all supporting materials due by deadline. Fall quarter only.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers (UCLA Graduate Division minimums); international applicants must have comparable record in their mathematical education",
        "test": {"cls": "GRE MATH SUBJECT REQUIRED (UCLA Graduate Division catalog 2027-2028: 'GRE: Subject in Mathematics.' General GRE not listed as required. Department faculty note: 'The mathematics department requires the GRE subject exam. It is rare for a student to be admitted to our program without this score.' ETS institution 4837. 3 LOR from mathematicians or professionals in related fields; SOP; transcripts.)"},
        "tui": "UCLA Graduate Division typically offers multi-year fully-funded support to admitted Mathematics PhD students through Teaching Assistantships, Research Assistantships, and fellowship awards (NSF GRFP, UCLA Dissertation Year Fellowship, etc.).",
        "url": "details/ucla-math-phd.html",
    },
    {
        "id": "duke-math-phd",
        "s": "duke",
        "n": "数学博士",
        "en": "PhD in Mathematics (Duke University, Graduate School, Department of Mathematics; 100% of financial-aid students receive funding; research spans pure and applied mathematics with interdisciplinary collaborations at Duke Medical School; 4 National Academy of Science members and 2 National Academy of Engineering members on faculty; $3.7M annual research funding; located in Durham, NC)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5 years; Fall admission only; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Durham, NC)",
        "ddl": "Fall 2027: application opens September 2026. **Deadline December 15, 2026, 11:59:59 p.m. Eastern Standard Time (EST)**. Some programs may continue accepting applications after deadline if spaces are available; contact department to confirm.",
        "lang": "TOEFL iBT minimum 90 (for exams taken before January 21, 2026; for exams on or after that date, minimum TOEFL iBT score per Duke Graduate School); IELTS minimum overall 7.0; Duolingo English Test minimum 125; test waiver may apply for some applicants",
        "test": {"cls": "GRE GENERAL OPTIONAL, MATH SUBJECT OPTIONAL (Duke Mathematics: 'Submission of the General and Math Subject GRE exams are both optional.' The Graduate School states: for GRE-optional programs, applicants may still submit scores if they feel they enhance their application. ETS institution 5116. 3 LOR; SOP; Resume; transcripts.)"},
        "tui": "Duke Graduate School reports 100% of Mathematics PhD students receiving financial aid. Support typically includes full tuition, stipend, and health insurance through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards (NSF GRFP, Duke Fellowship, etc.). Fee waiver available for eligible applicants through the online application.",
        "url": "details/duke-math-phd.html",
    },
]

DETAIL_TEMPLATE = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{school} - {en}</title>
<style>
body{{font-family:-apple-system,'Segoe UI',Roboto,sans-serif;max-width:960px;margin:24px auto;padding:0 20px;color:#222;line-height:1.6}}
h1{{font-size:24px;border-bottom:2px solid #1a73e8;padding-bottom:8px}}
h2{{font-size:18px;color:#1a73e8;margin-top:24px}}
.card{{background:#f8f9fa;border-left:4px solid #1a73e8;padding:12px 16px;margin:12px 0;border-radius:4px}}
.meta{{display:grid;grid-template-columns:120px 1fr;gap:6px 12px;font-size:14px}}
.meta b{{color:#555}}
ul{{margin:6px 0;padding-left:20px}}
.note{{background:#fff3cd;border-left-color:#ffc107;padding:10px 14px;margin-top:16px;font-size:13px}}
a{{color:#1a73e8}}
</style>
</head>
<body>
<h1>{school} - {en}</h1>
<div class="card">
<div class="meta">
<b>Degree</b><span>{deg}</span>
<b>Level</b><span>Research Doctorate (PhD)</span>
<b>STEM</b><span>{stem_label}</span>
<b>Duration</b><span>{dur}</span>
<b>Deadline</b><span>{ddl}</span>
<b>Language</b><span>{lang}</span>
<b>Standardized</b><span>{test_cls}</span>
<b>Funding</b><span>{tui}</span>
</div>
</div>

<h2>Program Overview</h2>
<div class="card">
{overview}
</div>

<h2>Admissions Requirements</h2>
<div class="card">
{requirements}
</div>

<h2>Research Areas</h2>
<div class="card">
{research}
</div>

<h2>Official Source</h2>
<div class="card">
{source}
</div>

<div class="note">
<strong>Note:</strong> Third batch of basic-science PhD sweep (NYU Courant, Brown, UMich, UCLA, Duke Mathematics PhD). Continues the Math PhD GRE policy divergence finding from Rounds 248-249. This batch leans GRE-free: NYU, Brown, UMich, and Duke all treat GRE General as optional (NYU and Duke also treat Math Subject as optional); UCLA Graduate Division 2027-2028 catalog still requires GRE Math Subject. Deadlines range from Dec 13 (UCLA) to Dec 15 (UMich, Duke) to Dec 18/Jan 4 (NYU) to Jan 1, 2027 (Brown). All 5 programs are STEM-designated, on-campus residential, and Fall admission only. Important distinctions: (1) Brown Mathematics (pure, Jan 1, General optional, Subject optional) is NOT the same as Brown Applied Mathematics (Dec 9, General required, Subject highly recommended) - this entry is pure math only. (2) NYU Mathematics PhD (Dec 18 strong rec / Jan 4 final) is NOT the same as NYU Atmosphere Ocean Science (AOS) Math PhD (which asks applicants to 'please do not submit' GRE). (3) UMich Mathematics has two PhD tracks (Mathematics and Applied & Interdisciplinary Mathematics); MS is self-funded, GSI reserved for PhD. (4) UCLA MA/MAT programs suspended indefinitely - only PhD admits. (5) Duke Mathematics reports 100% of financial-aid students receive funding.
</div>
</body>
</html>
"""

PAGES = {
    "nyu-math-phd": {
        "school": "New York University, Graduate School of Arts and Science, Courant Institute of Mathematical Sciences",
        "en": "PhD in Mathematics (Courant Institute)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Typically 5 years; 72 credits by end of Year 4; Written Comprehensive grade A; Oral Preliminary; dissertation defense; on-campus (Greenwich Village, NYC); Fall admission only",
        "ddl": "Fall 2027: strong rec Dec 18, 2026 5pm ET; final Jan 4, 2027 5pm ET. No rolling admissions.",
        "lang": "TOEFL iBT 100 / IELTS 7.0 recommended; waiver for accredited English-instructed degree; ETS school code 2596; dept 0703 Math; TOEFL dept 72",
        "test_cls": "GRE General and Subject both OPTIONAL (NYU GSAS: 'PhD in Mathematics: optional.' Dept views scores as useful but absence not penalized. 3 LOR at least 2 from math/science faculty.)",
        "tui": "NYU GSAS multi-year fully-funded support: tuition scholarship + stipend through GA, Teaching Fellowship, and research grants. GPA 3.0+ required; 2/3 of attempted credits completed.",
        "overview": "The New York University Department of Mathematics at the Courant Institute of Mathematical Sciences offers a PhD program. The Courant Institute is one of the world's leading centers for applied mathematics, mathematical physics, and computer science, but the PhD program in Mathematics also covers pure mathematics. Both the Mathematics and Atmosphere Ocean Science (AOS) PhD programs share fundamental requirements: 72 credits by the end of the 4th year, a Written Comprehensive Examination with a grade of A, an Oral Preliminary Examination, an Oral Defense of Dissertation, and a Doctoral Dissertation. GSAS requires students to maintain a GPA of 3.0 or higher and successfully complete at least two thirds of credit points attempted at NYU, excluding the current semester. Applications and all supporting materials must be submitted online by 5 p.m. Eastern Time. For Fall 2027, the strongly recommended deadline is December 18, 2026, and the final deadline is January 4, 2027. If a listed deadline falls on a Saturday, Sunday, or U.S. federal holiday, the next business day applies. Critically, for the PhD in Mathematics, GRE scores (both General and Mathematics Subject Test) are optional; the department views GRE scores as useful information, but applications which do not include these scores will not be at a disadvantage, and more weight will be placed on other elements. Note: the PhD in Atmosphere Ocean Science and Mathematics (AOS) is a separate program and asks applicants to 'please do not submit' GRE. Three letters of recommendation are required; it is strongly recommended that at least two letters be from faculty with whom the applicant took a mathematics or other science course. Applicants whose native language is not English must submit TOEFL (sub-600 paper / 250 computer / 100 iBT generally not recommended for admission); IELTS scores are accepted by GSAS in place of TOEFL. ETS school code is 2596; department code for GRE is 0703; for TOEFL it is 72.",
        "requirements": "<ul><li>Bachelor's degree in mathematics or related quantitative field</li><li>GRE General optional (not required; absence not penalized)</li><li>GRE Mathematics Subject optional (not required; absence not penalized)</li><li>ETS school code 2596 (NYU Grad Arts Sci)</li><li>Dept code 0703 (Math); TOEFL dept code 72</li><li>TOEFL iBT 100 recommended (paper 600 / computer 250); IELTS 7.0 accepted</li><li>Waiver for accredited English-instructed degree</li><li>NYU GSAS online application</li><li>Statement of Purpose</li><li>CV/Resume</li><li>3 letters of recommendation (at least 2 from math/science faculty)</li><li>Transcripts</li><li>**Strongly recommended deadline December 18, 2026, 5:00 p.m. ET**</li><li>**Final deadline January 4, 2027, 5:00 p.m. ET**</li><li>Fall admission only</li><li>72 credits by end of Year 4</li><li>Written Comprehensive Exam (grade A)</li><li>Oral Preliminary Exam; Oral Defense of Dissertation</li><li>Maintain GPA 3.0+; complete at least 2/3 of attempted credits</li><li>On-campus residential (Greenwich Village, NYC)</li></ul>",
        "research": "<ul><li>Pure mathematics (algebra, analysis, geometry, topology, number theory)</li><li>Applied mathematics (Courant Institute strength)</li><li>Mathematical physics</li><li>Numerical analysis and scientific computing</li><li>Partial differential equations</li><li>Probability and stochastic processes</li><li>Scientific computing and computational math</li><li>Mathematical finance (academic research)</li><li>Access to NYU-ECNU Institute of Mathematical Sciences and NYU Shanghai</li></ul>",
        "source": '<a href="https://gsas.nyu.edu/admissions/arc/programs/mathematics.html" target="_blank">NYU GSAS: Mathematics (PhD in Mathematics: GRE optional; strong rec Dec 18; final Jan 4; 5pm ET; AOS Math PhD separate - please do not submit GRE; TOEFL/IELTS; 3 LOR)</a> | <a href="https://math.nyu.edu/dynamic/graduate/ms-gsas/admission/" target="_blank">NYU Courant Math Admissions (GRE General+Subject optional; absence not penalized; TOEFL 100 iBT / 600 paper / 250 computer; IELTS accepted; ETS 2596; dept 0703; TOEFL dept 72; 3 LOR at least 2 from math/science faculty)</a> | <a href="https://math.nyu.edu/media/math/filer_public/df/de/dfde8634-018e-4990-921a-01d99bf7c646/guidebook_for_phd_students_in_math_at_courant_2_24_2026.pdf" target="_blank">NYU Courant PhD Guidebook (Feb 24, 2026 update; 72 credits by end of Year 4; Written Comprehensive grade A; Oral Preliminary; Oral Defense; GPA 3.0+; 2/3 credits completed)</a> | <a href="https://gsas.nyu.edu/admissions/arc/test-scores.html" target="_blank">NYU GSAS Test Scores (ETS school code 2596; GRE accepted on computer-based; TOEFL/IELTS; recommended TOEFL 100 iBT / IELTS 7.0; GSAS does not set minimum scores)</a>',
    },
    "brown-math-phd": {
        "school": "Brown University, Graduate School, Department of Mathematics (pure mathematics division)",
        "en": "PhD in Mathematics (pure math)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Typically 5 years; core courses in differentiable manifolds, real functions, complex functions, algebra, topology; on-campus (Providence, RI); Fall admission only",
        "ddl": "Fall 2027: application opens September 8, 2026. **Deadline January 1, 2027, 11:59 p.m. ET**. New feature: applicant uploads a short video.",
        "lang": "TOEFL iBT / IELTS Academic required for applicants from non-English-speaking countries; exemption for one+ year of study in an English-speaking country",
        "test_cls": "GRE General NOT REQUIRED, Math Subject ENTIRELY OPTIONAL (Brown Mathematics: 'Brown no longer requires the General GRE. The mathematics Subject GRE is entirely optional.' ETS code 3094. Note: Brown Applied Mathematics Division is SEPARATE - Dec 9 deadline, General required, Subject highly recommended.)",
        "tui": "Brown Graduate School multi-year fully-funded support for Mathematics PhD students: full tuition + stipend + health insurance through TA/RA/fellowship. Small cohort 30-40 students enables close faculty contact.",
        "overview": "The Brown University Department of Mathematics (pure mathematics division) offers a PhD program designed to prepare students with a broad knowledge of mathematics on an undergraduate level for a career in mathematical research and instruction. The program has a relatively small enrollment of 30 to 40 students, which permits small classes and close contact with faculty. Applicants should have a good background in undergraduate mathematics, regardless of their majors; students with backgrounds in advanced mathematics will find the program quite flexible. Visits to Brown and direct communication with the Director of Graduate Study are strongly encouraged. The core courses are in differentiable manifolds, real functions, complex functions, algebra, and topology. Other courses offered each year are in P.D.E., probability, algebraic geometry, number theory, and differential geometry. The library contains one of the finest mathematical collections available anywhere. The department has extensive computing facilities. Admission is very competitive: in recent years there have been well over 400 applications, and the department estimates that it makes about 15 offers of admission for fall. For Fall 2027, applications open September 8, 2026 and the deadline is January 1, 2027 at 11:59 p.m. Eastern. Critically, Brown no longer requires the General GRE; the mathematics Subject GRE is entirely optional. For applicants from non-English-speaking countries, an English proficiency score (TOEFL or IELTS) is required; this does not apply to applicants who have already completed one or more years of study in an English-speaking country. The application for Fall 2027 has a new feature: the applicant uploads a short video in addition to the written materials. IMPORTANT DISTINCTION: This entry is for the Department of Mathematics (pure mathematics). Brown's Division of Applied Mathematics is a SEPARATE PhD program with a December 9, 2026 deadline, where GRE General is required and the Mathematics Subject Test is highly recommended; that program is not covered in this entry.",
        "requirements": "<ul><li>Bachelor's degree; good background in undergraduate mathematics (not necessarily a math major)</li><li>GRE General NOT required (Brown no longer requires General GRE)</li><li>GRE Mathematics Subject entirely optional</li><li>ETS code 3094 (Brown University)</li><li>TOEFL iBT / IELTS Academic required for non-English-speaking countries</li><li>Exemption for one+ year of study in English-speaking country</li><li>Brown Graduate School online application (opens September 8, 2026)</li><li>Statement (research interests; consonant with faculty interests)</li><li>Curriculum vitae</li><li>Letters of recommendation</li><li>Transcripts</li><li>**NEW for Fall 2027: short video upload in addition to written materials**</li><li>**Deadline January 1, 2027, 11:59 p.m. ET**</li><li>Fall admission only</li><li>Small enrollment 30-40 students</li><li>~15 offers from 400+ applications (highly competitive)</li><li>Core courses: differentiable manifolds, real functions, complex functions, algebra, topology</li><li>On-campus residential (Providence, RI)</li></ul>",
        "research": "<ul><li>Differentiable manifolds</li><li>Real functions and analysis</li><li>Complex functions</li><li>Algebra</li><li>Topology</li><li>Partial differential equations</li><li>Probability</li><li>Algebraic geometry</li><li>Number theory</li><li>Differential geometry</li><li>Commitment to diversity/equity/inclusion work and mathematics as a community endeavor</li></ul>",
        "source": '<a href="https://mathematics.brown.edu/graduate/graduate-program-admission" target="_blank">Brown Mathematics Graduate Admission (Jan 1 deadline; General GRE not required; Math Subject entirely optional; TOEFL/IELTS; Fall 2027 new short-video upload; ~15 offers from 400+ apps; 30-40 students; core courses in differentiable manifolds, real/complex functions, algebra, topology)</a> | <a href="https://graduateprograms.brown.edu/graduate-program/mathematics-phd" target="_blank">Brown Graduate Programs: Mathematics (PhD) (GRE Subject Not required; GRE General Not required; deadline January 1, 2027; 30-40 students; small classes; close faculty contact; core courses listed)</a> | <a href="https://apply.graduateschool.brown.edu/portal/program_explorer" target="_blank">Brown Graduate Program Explorer (Mathematics Doctoral opens 09/08/2026; deadline 01/01/2027; Applied Mathematics Doctoral opens 09/08/2026; deadline 12/09/2026 - separate program)</a>',
    },
    "umich-math-phd": {
        "school": "University of Michigan, Rackham Graduate School, College of Literature, Science, and the Arts, Department of Mathematics",
        "en": "PhD in Mathematics (or Applied & Interdisciplinary Mathematics track)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Typically 5 years; Fall term only; Qualifying Review; Preliminary Exam by start of Year 4; Candidacy by end of Year 3; dissertation; on-campus (Ann Arbor, MI)",
        "ddl": "Fall 2027: application opens September 2026. **Deadline December 15, 2026** for PhD (MS deadline February 1, 2027). Applications only accepted for Fall term. All decisions no later than April 15, 2027.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers; scores no older than two years as of Admission Deadline; TOEFL iBT Special Home Edition and IELTS Indicator accepted; minimum scores per Rackham rules",
        "test_cls": "GRE General NOT REQUIRED (Rackham policy), Math Subject STRICTLY OPTIONAL (UMich Mathematics: 'GRE General Test scores are no longer included in the admission process in accordance with a policy of the Rackham Graduate School. GRE Mathematics Subject Test scores are strictly optional; however, if an applicant chooses so, they may submit them as a combined PDF file with their transcript or personal statement.' ETS Rackham code 1839.)",
        "tui": "All admitted PhD students receive full support through GSI (Graduate Student Instructorship), GSR (Graduate Student Research Assistantship), and fellowships. MS program is self-funded; GSI positions reserved for PhD students.",
        "overview": "The University of Michigan Department of Mathematics offers two PhD tracks: PhD in Mathematics and PhD in Applied & Interdisciplinary Mathematics (AIM). The Michigan Mathematics Department has consistently been ranked as one of the top ten Mathematics Departments in the country. For the 2026-2027 academic year, the department has 155 Mathematics graduate students, of whom 46 are women or non-binary. Approximately 83% of graduate students are enrolled in the PhD program. All of these students received support from the Department in the form of Graduate Student Instructorships, Graduate Student Research Assistantships, and fellowships. The Mathematics Department offers 5 Master's degrees and 2 PhD programs. The department also offers the Marjorie Lee Browne (MLB) Scholars Program, which is an enhanced option for the M.S. degree in either Mathematics or Applied and Interdisciplinary Mathematics for eligible students to prepare for continuing toward a PhD. For the PhD program, the Fall 2027 application window is open; the application deadline is December 15, 2026. The MS application deadline is February 1, 2027. The graduate programs only accept applications for Fall semesters (no Winter, Spring/Summer). Critically, GRE General Test scores are no longer included in the admission process in accordance with a policy of the Rackham Graduate School. GRE Mathematics Subject Test scores are strictly optional; however, if an applicant chooses so, they may submit them as a combined PDF file with their transcript or personal statement. TOEFL or IELTS exam is required for students whose native language is not English; scores should not be older than two years as of the Admission Deadline. Minimum TOEFL and IELTS scores must meet Rackham's requirements. ETS school code for the University of Michigan Rackham Graduate School is 1839. The median time to degree for Math PhD is a standard 5-year completion. Stage 2 of the PhD program commences with successful completion of the Qualifying Review and finishes with admission to Candidacy; Rackham rules require students to achieve candidacy by the end of the third year. The Preliminary Examination is the most important requirement for achieving Candidacy; students are expected to complete their Preliminary Examination and advance to Candidacy by the start of the fourth year. Once the Preliminary Examination is completed, a graduate student will be eligible to advance to candidacy. After that, the PhD degree requires students to enroll each fall and winter term for 8 credits of Math 995 under the supervision of their advisor. The Admissions committee makes decisions as they review applications; the review process continues through April, and all decisions are made no later than April 15. Students admitted to the Math PhD program have a background roughly equivalent to U of M honors mathematics undergraduates. Applied Math is part of the Mathematics PhD and Mathematics MS programs. Students who will have completed a Master's degree in Mathematics by the time they begin studies at the University of Michigan must apply to the PhD program (not the MS).",
        "requirements": "<ul><li>Bachelor's degree; background roughly equivalent to UMich honors mathematics undergraduate</li><li>GRE General NOT required (per Rackham Graduate School policy)</li><li>GRE Mathematics Subject strictly optional (submit as combined PDF with transcript or personal statement)</li><li>ETS Rackham code 1839</li><li>TOEFL iBT / IELTS Academic required for non-native English speakers</li><li>Scores no older than two years as of Admission Deadline</li><li>TOEFL iBT Special Home Edition and IELTS Indicator accepted</li><li>Minimum scores per Rackham rules</li><li>Rackham Graduate School online application (opens September 2026)</li><li>Statement of purpose</li><li>Letters of recommendation</li><li>Transcripts</li><li>**PhD deadline December 15, 2026** (MS deadline February 1, 2027)</li><li>Fall term only (no Winter/Spring/Summer)</li><li>Two PhD tracks: Mathematics / Applied & Interdisciplinary Mathematics (AIM)</li><li>Qualifying Review; Preliminary Exam by start of Year 4; Candidacy by end of Year 3</li><li>After candidacy: enroll 8 credits Math 995 each Fall/Winter with advisor</li><li>All PhD students fully funded (GSI/GSR/fellowship)</li><li>MS program self-funded; GSI reserved for PhD</li><li>All decisions by April 15, 2027</li><li>On-campus residential (Ann Arbor, MI)</li></ul>",
        "research": "<ul><li>Pure mathematics (algebra, analysis, geometry, topology, number theory, logic)</li><li>Applied mathematics and interdisciplinary mathematics (AIM track)</li><li>Dynamical systems</li><li>Probability</li><li>Mathematical biology</li><li>Scientific computing</li><li>Mathematical physics</li><li>Combinatorics</li><li>Close ties with Statistics, EECS, Physics, and the Applied Interdisciplinary Mathematics program</li></ul>",
        "source": '<a href="https://lsa.umich.edu/math/graduates/Admissions/applying.html" target="_blank">UMich Math PhD Admissions (Dec 15, 2026; GRE General no longer included per Rackham; Math Subject strictly optional; TOEFL/IELTS required; ETS 1839; Fall only; application window open)</a> | <a href="https://lsa.umich.edu/math/graduates/Admissions/applying/graduate-admissions-frequently-asked-questions.html" target="_blank">UMich Math PhD FAQ (Fall admission only; PhD recommended - generally fully funded GSI; MS self-funded; GRE General no longer included; Math Subject optional; all decisions by April 15)</a> | <a href="https://lsa.umich.edu/math/graduates/Admissions.html" target="_blank">UMich Math Admissions overview (155 grad students; 46 women/non-binary; ~83% in PhD; all PhD funded; 5 MS + 2 PhD programs; MLB Scholars enhanced MS option; median time to degree)</a> | <a href="https://lsa.umich.edu/math/graduates/GraduateStudentHandbook/doctoral-programs/ph-d-programs1/ph-d--program-requirements/stage-2.html" target="_blank">UMich Math PhD Stage 2 Handbook (Qualifying Review; Preliminary Exam by start of Year 4; Candidacy by end of Year 3; Math 995 8 credits Fall/Winter after candidacy)</a> | <a href="https://rackham.umich.edu/programs-of-study/?deg%5B%5D=8" target="_blank">Rackham Programs of Study (Mathematics PhD code 00278; Applied & Interdisciplinary Mathematics code; Fall Dec 15 for PhD; Feb 1 for MS)</a>',
    },
    "ucla-math-phd": {
        "school": "University of California Los Angeles, Graduate Division, Department of Mathematics",
        "en": "PhD in Mathematics (PhD only; MA/MAT suspended indefinitely)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus (Los Angeles, CA); Fall quarter admission only",
        "ddl": "Fall 2027: application opens September 2026. **Deadline December 13, 2026** (department page; grad.ucla.edu catalog also lists December 15). Application review begins late December. Fall quarter only.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers (UCLA Graduate Division minimums); international applicants must have comparable record in their mathematical education",
        "test_cls": "GRE MATH SUBJECT REQUIRED (UCLA Graduate Division catalog 2027-2028: 'GRE: Subject in Mathematics.' General not listed as required. Dept faculty note: 'The mathematics department requires the GRE subject exam. It is rare for a student to be admitted to our program without this score.' ETS institution 4837. 3 LOR from mathematicians or professionals in related fields.)",
        "tui": "UCLA Graduate Division multi-year fully-funded support through TA, RA, and fellowship awards (NSF GRFP, UCLA Dissertation Year Fellowship).",
        "overview": "The UCLA Department of Mathematics offers the Doctor of Philosophy (PhD) degree in Mathematics. The Master of Arts (M.A.) and Master of Arts in Teaching (M.A.T.) programs have been suspended indefinitely; if students are interested in doing graduate work in the department, they must apply for admission to the PhD program. Applications are accepted for Fall quarter matriculation only. The application deadline is December 13 (department page; grad.ucla.edu 2027-2028 catalog also lists December 15). Application review process begins in late December; to ensure full consideration, applications should be complete, with all supporting material submitted, by that time. The minimum Department requirements for applicants, in addition to the minimum University requirements, are: a bachelor's degree or its equivalent, to be completed by the time of matriculation, with a minimum B (3.0 on a 4.0 scale) GPA in undergraduate junior/senior years and in post baccalaureate work. Applicants for the PhD program must have a 3.5 GPA in upper division math courses. Prospective students do not need to have an undergraduate mathematics major, but must complete at least 12-quarter, or 8-semester courses in substantial upper division mathematics. According to the UCLA Graduate Division 2027-2028 Admission Requirements catalog for the graduate major in Mathematics (major code 0540), the exams & GRE types listed is 'GRE: Subject in Mathematics.' Three letters of recommendation are required from mathematicians or professionals in related fields who know the applicant's recent work. All applicants are expected to submit the departmental application and a statement of purpose. Although prospective graduate students in mathematics need not have an undergraduate mathematics major, they must have completed at least 12 quarter courses (or eight semester courses) in substantial upper division mathematics, particularly advanced calculus, algebra, differential equations, and differential or projective geometry. PhD applicants must present a grade-point average of at least 3.5 in upper division mathematics courses. Applicants who have already obtained a master's degree must have maintained an average of better than 3.5 in graduate study. International applicants should have at least a comparable record in their mathematical education. Exceptions to these requirements are granted only in cases where exceptional ability in quantitative science has been demonstrated. The department admits only PhD applicants. UCLA Mathematics faculty note that the department is very focused on test scores, most notably the GRE subject exam score and also the TOEFL; the GRE subject exam is a yardstick used to gauge the likelihood that a student will pass the basic qualifying exam upon entrance. The department also looks at the general GRE to get a sense of writing ability and basic math. Because many students TA in their first year, the TOEFL is critical to ensure the student can speak English. The Department of Mathematics is located at 6356 Math Sciences, Box 951555, Los Angeles, CA 90095-1555; phone (310) 825-4971.",
        "requirements": "<ul><li>Bachelor's degree completed by time of matriculation</li><li>Minimum B (3.0/4.0) GPA in junior/senior undergrad and postbac work</li><li>**PhD: minimum 3.5 GPA in upper-division mathematics courses**</li><li>If already have a master's degree: average better than 3.5 in graduate study</li><li>12 quarter (or 8 semester) upper-division math courses (advanced calculus, algebra, differential equations, differential/projective geometry)</li><li>Undergraduate mathematics major not required</li><li>**GRE Mathematics Subject Test REQUIRED** per grad.ucla.edu 2027-2028 catalog</li><li>GRE General not listed as required (but department faculty note they look at it for writing/basic math)</li><li>ETS institution 4837 (UCLA)</li><li>TOEFL iBT / IELTS Academic required for non-native English speakers</li><li>UCLA Graduate Division online application</li><li>Departmental application</li><li>Statement of purpose</li><li>3 letters of recommendation from mathematicians or professionals in related fields</li><li>Transcripts</li><li>**Deadline December 13, 2026** (department page; catalog also lists December 15)</li><li>Fall quarter only (no Winter/Spring/Summer)</li><li>PhD only (MA and MAT suspended indefinitely)</li><li>On-campus residential (Los Angeles, CA)</li></ul>",
        "research": "<ul><li>Pure mathematics (algebra, analysis, geometry, topology, number theory, logic)</li><li>Applied mathematics</li><li>Mathematical physics</li><li>Probability</li><li>Numerical analysis</li><li>Partial differential equations</li><li>Combinatorics</li><li>Mathematical biology</li><li>Financial mathematics (academic research)</li></ul>",
        "source": '<a href="https://ww3.math.ucla.edu/admissions/" target="_blank">UCLA Mathematics Admissions (Dec 13 deadline; Fall only; MA/MAT suspended indefinitely; PhD only; minimum 3.5 GPA upper-division math; 12 quarter or 8 semester upper-division math; 3 LOR; ETS 4837)</a> | <a href="https://grad.ucla.edu/requirements/?app=admission&major=0540" target="_blank">UCLA Graduate Division 2027-2028 Admission Requirements: Mathematics major 0540 (deadline Dec 13, 2026; admission limited to Fall; exams & GRE types: Subject in Mathematics; 3 LOR; 3.5 GPA upper-division math; 12 quarter / 8 semester upper-division math)</a> | <a href="https://grad.ucla.edu/graduate-program-requirements/program-requirements-for-mathematics-2/" target="_blank">UCLA Program Requirements for Mathematics (department address 6356 Math Sciences Box 951555; phone 310-825-4971; GRE General and Subject in Mathematics; 3 LOR; MA/MAT listed but suspended)</a>',
    },
    "duke-math-phd": {
        "school": "Duke University, Graduate School, Department of Mathematics",
        "en": "PhD in Mathematics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Mathematical Sciences / CIP 27.0101)",
        "dur": "Typically 5 years; Fall admission only; coursework; preliminary and qualifying exams; dissertation; on-campus (Durham, NC)",
        "ddl": "Fall 2027: application opens September 2026. **Deadline December 15, 2026, 11:59:59 p.m. Eastern Standard Time (EST)**. Some programs may continue accepting applications after deadline if spaces are available; contact department to confirm.",
        "lang": "TOEFL iBT minimum 90 (exams before Jan 21, 2026; new minimums for exams on/after that date); IELTS minimum overall 7.0; Duolingo English Test minimum 125; test waiver may apply for some applicants",
        "test_cls": "GRE GENERAL OPTIONAL, MATH SUBJECT OPTIONAL (Duke Mathematics: 'Submission of the General and Math Subject GRE exams are both optional.' For GRE-optional programs, applicants may still submit scores if they feel they enhance their application. ETS institution 5116. 3 LOR; SOP; Resume; transcripts.)",
        "tui": "Duke reports 100% of Mathematics PhD students receiving financial aid. Support typically includes full tuition, stipend, and health insurance through RA, TA, and fellowship awards (NSF GRFP, Duke Fellowship). Fee waiver available for eligible applicants through online application.",
        "overview": "The Duke University Department of Mathematics offers a PhD program spanning pure and applied mathematics. The graduate program in Mathematics at Duke offers research training in a wide variety of topics in mathematics. Major areas of research specialization include algebra, number theory, algebraic geometry, analysis, differential geometry, applied mathematics, probability, combinatorics, partial differential equations, and mathematical biology. The program has consistently been ranked among the top 20 nationally by U.S. News & World Report. The faculty conduct more than $3.7 million in research each year for industry, the Department of Defense, the National Science Foundation, and the National Institutes of Health. The department includes four National Academy of Science members and two National Academy of Engineering members. The PhD program offers research training in a wide variety of topics in mathematics, with research efforts often including collaborations with researchers in the medical school and other Duke departments. This interdisciplinary nature and breadth of research areas make the department an ideal place to prepare for a research career in academia or broader directions in advanced science and technology. For Fall 2027 admission, applications are due by Tuesday, December 15, 2026. Critically, submission of the General and Math Subject GRE exams are both optional. The Graduate School notes that for GRE-optional programs, applicants may still submit scores if they feel they enhance their application; applicants who choose to enter self-reported test scores will have official test scores become a required component of the application. Applications to the program are administered by the Graduate School (not the Math Department); all logistical questions should be directed to the Graduate School. The Math Director of Graduate Studies (DGS) can answer questions about academic aspects of the program. An application fee waiver may be available to applicants who meet certain criteria set out by The Graduate School; the fee waiver option is built into the application system. The Graduate School requires 3 letters of recommendation, a Statement of Purpose (with department guidance), a Resume, and transcripts (unofficial with application, official upon admission). English language requirement: TOEFL iBT, IELTS, or Duolingo English Test required for applicants whose first language is not English; the Graduate School generally seeks scores no less than 90 for the iBT (exams before January 21, 2026; new minimums for exams on or after that date), 7.0 for IELTS, or 125 for Duolingo. The Department reports that 100% of students receiving financial aid are supported.",
        "requirements": "<ul><li>Bachelor's degree in mathematics or related quantitative field</li><li>GRE General optional (not required; may submit to enhance application)</li><li>GRE Mathematics Subject optional (not required; may submit to enhance application)</li><li>ETS institution 5116 (Duke University)</li><li>TOEFL iBT 90 minimum (exams before Jan 21, 2026; new minimums for exams on/after that date)</li><li>IELTS overall 7.0 minimum</li><li>Duolingo English Test 125 minimum</li><li>Test waiver may apply for some applicants</li><li>Duke Graduate School online application (opened September 2026)</li><li>Statement of Purpose (per department guidance)</li><li>Resume/CV (required)</li><li>3 letters of recommendation (required)</li><li>Unofficial transcripts with application; official transcripts required upon admission</li><li>Undergraduate GPA on 4.0 scale required</li><li>Fee waiver available through online application for eligible applicants</li><li>**Deadline December 15, 2026, 11:59:59 p.m. EST**</li><li>Fall admission only (application terms: Fall)</li><li>100% of financial-aid PhD students receive funding</li><li>Interdisciplinary collaborations with Duke Medical School and other departments</li><li>4 NAS members + 2 NAE members on faculty</li><li>$3.7M annual research funding</li><li>On-campus residential (Durham, NC)</li></ul>",
        "research": "<ul><li>Algebra</li><li>Number theory</li><li>Algebraic geometry</li><li>Analysis</li><li>Differential geometry</li><li>Applied mathematics</li><li>Probability</li><li>Combinatorics</li><li>Partial differential equations</li><li>Mathematical biology (interdisciplinary with Duke Medical School)</li><li>Cross-departmental research with Duke Physics, CS, ECE, and the Medical School</li></ul>",
        "source": '<a href="https://math.duke.edu/graduate/apply" target="_blank">Duke Mathematics How to Apply (Dec 15, 2026; General and Math Subject GRE both optional; 3 LOR; SOP; Resume; fee waiver available; administered by Graduate School)</a> | <a href="https://gradschool.duke.edu/academics/programs-degrees/mathematics/" target="_blank">Duke Graduate School: PhD in Mathematics (100% financial aid; Fall only; Dec 15 deadline; GRE General optional; GRE Subject Math optional; TOEFL/IELTS/Duolingo required; 3 LOR; SOP; Resume; unoffical transcripts)</a> | <a href="https://gradschool.duke.edu/admissions/application-deadlines/" target="_blank">Duke Graduate School Application Deadlines (all deadlines 11:59:59pm EST; Mathematics PhD Dec 15; some programs continue accepting after deadline if spaces available)</a> | <a href="https://gradschool.duke.edu/admissions/application-instructions/gre-scores/" target="_blank">Duke Graduate School GRE Scores (GRE-optional programs may still submit scores; self-reported scores trigger official score requirement; scores must not be more than 5 years old from August 1 of application year)</a>',
    },
}

# Write detail pages
for p in PROGRAMS:
    key = p["id"]
    d = PAGES[key]
    html = DETAIL_TEMPLATE.format(
        school=d["school"], en=d["en"], deg=d["deg"], stem_label=d["stem_label"],
        dur=d["dur"], ddl=d["ddl"], lang=d["lang"], test_cls=d["test_cls"], tui=d["tui"],
        overview=d["overview"], requirements=d["requirements"],
        research=d["research"], source=d["source"],
    )
    path = os.path.join(DET, key + ".html")
    with open(path, "w", encoding="utf-8") as f:
        f.write(html)
    print(f"Wrote: {key}.html")

# Append PROGRAMS
idx_path = os.path.join(BASE, "index_main.html")
with open(idx_path, "r", encoding="utf-8") as f:
    html = f.read()

def build_entry(p):
    return ('{{id:"{id}",s:"{s}",n:"{n}",en:"{en}",deg:"{deg}",lvl:"{lvl}",stem:{stem},'
            'dur:"{dur}",ddl:"{ddl}",lang:"{lang}",test:{{cls:"{test_cls}"}},'
            'tui:"{tui}",url:"{url}"}}').format(
        id=p["id"], s=p["s"], n=p["n"], en=p["en"], deg=p["deg"], lvl=p["lvl"],
        stem=p["stem"], dur=p["dur"], ddl=p["ddl"], lang=p["lang"],
        test_cls=p["test"]["cls"].replace('"', "'"),
        tui=p["tui"].replace('"', "'"), url=p["url"],
    )

new_entries = ",\n".join(build_entry(p) for p in PROGRAMS)

m = re.search(r'const\s+PROGRAMS\s*=\s*\[', html)
start = m.end()
depth = 1
i = start
while i < len(html) and depth > 0:
    c = html[i]
    if c == '[': depth += 1
    elif c == ']': depth -= 1
    i += 1
insert_pos = i - 1
prefix = html[:insert_pos].rstrip()
suffix = html[insert_pos:]
if prefix.endswith('{'):
    new_block = prefix + "\n" + new_entries + "\n" + suffix
else:
    new_block = prefix + ",\n" + new_entries + "\n" + suffix

# Append VD on new_block (re-locate to avoid offset)
vd_entries = ",\n".join(f'"{p["url"]}"' for p in PROGRAMS)
m2 = re.search(r'VERIFIED_DETAILS\s*=\s*new\s+Set\s*\(\s*\[', new_block)
vstart = m2.end()
vdepth = 1
j = vstart
while j < len(new_block) and vdepth > 0:
    c = new_block[j]
    if c == '[': vdepth += 1
    elif c == ']': vdepth -= 1
    j += 1
vinsert_pos = j - 1
vprefix = new_block[:vinsert_pos].rstrip()
vsuffix = new_block[vinsert_pos:]
if vprefix.endswith(','):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
elif vprefix.endswith('['):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
else:
    new_block = vprefix + ",\n" + vd_entries + "\n" + vsuffix

with open(idx_path, "w", encoding="utf-8") as f:
    f.write(new_block)

print(f"Appended {len(PROGRAMS)} PROGRAMS entries and {len(PROGRAMS)} VD entries")
print(f"Done. File size: {os.path.getsize(idx_path)}")
