Open-source project
sjtug/SJTUThesis avatar
sjtug/SJTUThesis

The word count target is written into the build as a regular expression

Shanghai Jiao Tong University LaTeX Thesis Template.

3,910 stars791 forksTeXApache-2.0

At a glance

What is it?
SJTUThesis is a worked example thesis for a document class that lives in a separate repository. Its build picks a counting mode by grepping the preamble for a language option, which means the number printed depends on a pattern match rather than on the language you are actually writing in.
Who is it for?
SJTUThesis is the right choice if you are writing a thesis at that university and want the formatting conventions already applied, and it is a good example to read if you want to see how a document class is applied to a real document. Four things to know before you rely on it.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Activity is slowing. The repository last received commits 6 months ago.
What is it written in?
Mainly TeX, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • sjtug/SJTUThesis3,910 ★ · +46
Star history
Repository2026-09-242026-11-23
sjtug/SJTUThesis3.9k3.9k

46 Stars in the last 60 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The word count target chooses its counting mode by grepping the preamble

This is the most interesting thing in the build, and it is a genuine fragility rather than a style choice. The target has two counting modes. For a document whose documentclass line contains a language option whose value is English, it counts characters and prints a line labelled as the English character count. For everything else it counts Chinese characters and prints a line labelled as the pure Chinese character count. Then it unconditionally prints a third line, the total, as English words plus Chinese characters. The mode is selected by a grep against the source file, skipping comment lines, matching a documentclass line whose option list has no bracket immediately followed by a language assignment. That pattern is doing a lot of work in one expression. It has to know where the optional arguments end and the required ones begin, because it deliberately excludes a language option appearing inside the brackets. If someone writes the options in a different order, or splits them across lines, or uses a different command to load the class, the grep misses and a Chinese thesis gets a line labelled English character count. Nothing warns you. The number is simply wrong, and the only place it shows up is this target, so most people would never notice.

Two engines, one encoding, and a TeX distribution you are told to keep updating

The engine constraint is stated up front and it is narrow in a useful way: both XeTeX and LuaTeX are supported, and the character encoding supports UTF-8 only. Notably absent from that list is pdfLaTeX. That matters because the README later warns that online editors default to pdfLaTeX for new projects, so every user of a hosted editor has to change a setting before anything works. The distribution requirement is the part that will cost you the most time. The document class this template depends on is published on CTAN, so the template cannot be used without a TeX distribution that already contains it, and the README asks for the latest version rather than a minimum. It goes further and asks you to update the packages regularly, with the stated reason being to get the newest version of the class collection. So the template is versioned, but it is versioned against something you are expected to track yourself. A template whose dependency moves weekly is fine if you are a student who compiles once. It is a different proposition for a supervisor with forty students on forty machines, or anyone building a document in a container where the distribution is pinned for reproducibility.

This repository is the example, and the class that does the work is elsewhere

The README is explicit about the division, twice, and it is worth understanding before you file an issue in the wrong place. This repository is a user-facing example template, a complete implementation that demonstrates common typesetting cases including formulas, tables, algorithms and references. Users are invited to reference it or write their thesis directly on top of it. But the actual document class, and the collection it belongs to, live in a different repository under the same organisation. And the licence section makes the split legal as well as architectural: the class files are under the LaTeX Project Public Licence, while everything else is under Apache 2.0. A third element is separate again. The university owns the copyright in the logo and wordmark image files, which are named explicitly in the licence section and are not licensed under either open licence. So there are three regimes in one repository, and a commercialisation question about the logo does not have the same answer as a commercialisation question about the layout code.

Only the latest version is maintained, so there is no stable branch to pin

The download section says the template updates frequently and that only the latest version is maintained. That is a policy statement with real consequences, and it appears twice in different forms: once as an explanation of why you should upgrade before reporting a problem, and once as the reason the recommended download is a branch archive rather than a tagged release. The clone command and the archive link both point at the default branch, not at a version. So a template that is used to produce a document which gets submitted, printed and archived years later has no fixed point in its own repository. There are release tags in the history, so versions exist, but the documented path does not use them and the policy says older ones are not kept current. The reasoning is defensible: a thesis template that fixes bugs in one place is better for students than one where a third of users are on last year's version. The cost is that reproducibility of a compiled document is a property you have to create yourself, by keeping your own copy of the source and the distribution you used.

The build has a Windows branch, a visual target, and a phony dependency that forces a rebuild

The four commands the README documents are named identically on both platforms:

bash
make all                      # 编译生成 main.pdf
make clean                    # 删除编译所产生的中间文件
make cleanall                 # 删除 main.pdf 和所有中间文件
make wordcount                # 论文字数统计

Behind them the build file is short and each decision in it is deliberate. It defines a thesis basename so every target works on one variable. The compiler invocation passes four options: timestamps, file and line error reporting, halt on error, and a non-stop interaction mode, which means it will not stop to ask you a question in the middle of a document with a missing reference. A separate target adds precompiled constant rendering, which is the one to use while writing. The deletion commands are selected by testing for a Windows environment variable, so the same clean targets work on both platforms, and the command used to open the finished file is branched the same way. Every target is marked phony, including the dependency that forces the PDF target to rebuild. That last one is the interesting bit: the document is rebuilt every time rather than being skipped when the timestamp looks newer, which is the correct choice for a target where the source is assembled from several included files that make does not know about. The Windows batch script offers the same four commands with the same names, so the two platforms present one interface.

Editor support is a preset name in one extension and magic comments in another

Three editor paths are documented and they differ in how much you have to know. For a graphical code editor, install the LaTeX extension, then choose a named preset that compiles with the right engine, or change one setting so that preset is the default. That is a configuration step with a specific value to type, which is the right amount of instruction. For a dedicated TeX editor, the template ships magic comments that make it work with no configuration, which is better. The online editors are the awkward case. Two hosted services are linked with direct template pages, and for those the README says clicking the icon is enough. For any other hosted editor, including the university's own, you have to download the archive and upload it, and then change the compiler setting yourself, because hosted editors default to the engine this template does not support. So the same template is one click on two services, one setting on a desktop editor, and a download plus an upload plus a setting change everywhere else. The university running its own hosted editor for its own students, and that editor not defaulting to a supported engine, is the sort of detail this template cannot fix from the outside.

A mirror, two chat platforms, and an ordering of where to report a problem

The support section is unusually well organised, and the ordering is the interesting part. It ranks three channels by what kind of problem you have. Usage questions and compilation errors go to the discussions area, which is marked as the recommended channel. Bugs in the template and new feature requests go to the issue tracker. And for people who want to ask faster, two chat groups are listed, a QQ group with its number spelled out, and a Telegram group, which requires a two-step path because you have to follow a mirror site's announcement channel first to find the linked group. Before any of that, the README tells you to search the wiki and to use the search box in its corner. The wiki is also listed as a contribution target, on the grounds that anyone can edit it, which makes it the only documentation here with no review step. Two other things sit alongside. The clone instructions offer a university mirror as an alternative to the origin, which matters for users inside the network. And the contributing section explicitly asks for typographic examples rather than code, since this is the example repository, and points contributors with code to the other repository instead.

Editorial conclusion

SJTUThesis is the right choice if you are writing a thesis at that university and want the formatting conventions already applied, and it is a good example to read if you want to see how a document class is applied to a real document. Four things to know before you rely on it. Keep your own copy of the source, because only the latest version is maintained and the documented download is a branch archive rather than a tagged release, so nothing in the repository pins the version your document was built with. Update your TeX distribution before you debug anything, since the template asks for the latest packages specifically to get the newest class collection, and a compilation problem is more often a stale distribution than a template bug. Change the compiler setting on any hosted editor, because the default there is an engine this template does not support. And check the word count target's output rather than trusting it, since which counting mode it uses is decided by a pattern match against your preamble.

Frequently asked questions

What is SJTUThesis?

It is a complete worked example thesis for a Shanghai Jiao Tong University document class, demonstrating common typesetting cases such as formulas, tables, algorithms and references. Users can reference it or write their thesis directly on top of it. The document class itself lives in a separate repository and is published on CTAN, so this template requires a TeX distribution that already contains it.

Which LaTeX engines does SJTUThesis support?

XeTeX and LuaTeX, with UTF-8 as the only supported character encoding. PDFLaTeX is not supported, which matters because online editors commonly default to it for new projects, so hosted environments need the compiler setting changed before the template will build.

How do I build the SJTUThesis example?

On Linux and macOS the provided make targets handle it: one compiles the PDF, one cleans intermediates, one removes the PDF and the intermediates, and one prints a word count. On Windows a batch script offers the same four commands under the same names. A graphical code editor needs a specific compile preset selected, while the dedicated TeX editor works out of the box from magic comments in the template.

How does the SJTUThesis word count work?

The target inspects the document preamble with a pattern matching for a language option set to English. If it matches, it counts characters and labels the result as an English character count. Otherwise it counts Chinese characters and labels the result as a pure Chinese count. It then always prints a total of English words plus Chinese characters. The mode therefore depends on a pattern match, not on a declared setting.

What licence does SJTUThesis use?

Three regimes in one repository. The document class files are under the LaTeX Project Public Licence, everything else is under Apache 2.0, and the university retains copyright in its logo and wordmark image files, which are named in the licence section and are covered by neither open licence. The repository is maintained by a volunteer group at the university.

Official sources

  1. Issues
  2. License: Apache-2.0
  3. README
  4. Releases
  5. sjtug/SJTUThesis on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/sjtug-sjtuthesis.svg)](https://hysenlabs.com/projects/sjtug-sjtuthesis)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/sjtug-sjtuthesis.svg)](https://hysenlabs.com/projects/sjtug-sjtuthesis)

Was this useful?