1 Introduction
Late in the fall of 2022, I was contemplating updating my book, More Math into LATEX, fifth edition [1 G. Grätzer, More math into LATEX. (5th edition) Springer, New York (2016) ]. It was seven years old, and a lot had changed (as witnessed by [3 G. Grätzer, Text and math into LATEX. (6th edition) Springer, New York (2024) ]). Therefore, I started contemplating a sixth edition, which would be a huge undertaking. For instance, BibLaTex would be a new topic for the book. Its manual alone is about 350 pages and I would have to read at least ten like that.
Then the gods smiled at me. In November 2022, ChatGPT 3.5 was released; see my article [2 G. Grätzer, The gods smile at me: The LATEXcompanion, third edition, and ChatGPT. TUGBoat 44, 319–321 (2023) ]. Let me illustrate what ChatGPT 3.5 provides for a LATEX user.
ChatGPT in action
We start with two very simple uses of ChatGPT.
First, I ask ChatGPT: What is the end-of-line command?
latex what is the end-of-line command?
ChatGPT responds1Another time, the response may differ.:
The LaTeX command indicating the end of a line is \\. This command is used to break the line at the point of insertion. It’s commonly used in text environments, such as within a paragraph, or in tabular environments, like tables, to move to the next line. For example, in a paragraph:
This is some text. \\ More text
“More text.” will appear on the next line. In a table:
\begin{tabular}{cc} Cell1 & Cell2 \\ Cell3 & Cell4 \end{tabular}
Remember that \\ is a line break command and not a new paragraph command. To start a new paragraph, a blank line or the \par command is used.
How very nice.
Second, by mistake, you define a new command:
\newcommand{\vec}{...}.
! LaTeX Error: Command \vec already defined.
You can find out the definition of the \vec command by entering into interactive mode and typing
* \show \vec
LaTeX responds with:
> \vec=macro: ->\mathaccent "017E. <*> \show \vec
informing you that \vec is a command, and specifically, a math accent. This is not very intuitive. Now we use ChatGPT:
latex what is the \vec command?
The answer:
The \vec command in LaTeX is used to denote a vector. When this command is applied to a character or a group of characters in your LaTeX document, it places a small arrow above them. This is a common notation in mathematics and physics to indicate that the symbol represents a vector quantity. For example, writing \vec{x} in LaTeX will display the letter ‘x’ with an arrow over it, symbolizing that ‘x’ is a vector.
ChatGPT goes on with some illustrations.
I also consult ChatGPT on hyphenation, looking up strange phrases, and so on. You will find many uses of ChatGPT in this article.
ChatGPT hallucinations
While my experience with ChatGPT was very positive, experts were skeptical: “You know my opinion of ChatGPT and other large language models; they can be misleading and under certain circumstances, produce entirely captivating yet nonsensical and fabricated content.” This is usually called a ‘ChatGPT hallucination.’
Let us ask ChatGPT what this means:
A GPT hallucination refers to instances where a language model like GPT (Generative Pre-trained Transformer) generates text that is either factually incorrect, nonsensical, or unrelated to the input it was given. These hallucinations occur when the model makes errors in generating responses, often due to limitations in its training data or the inherent complexities of natural language processing.Here are a few key points about GPT hallucinations:
Based on patterns, not facts. GPT models are trained on large datasets of text and learn to predict the next word in a sequence based on patterns in the data. They do not have access to external information or real-world knowledge. This sometimes leads to the generation of text that seems plausible but is factually incorrect.
Context limitations. GPT models have a limited context window, which means they can only ‘see’ a certain number of words at a time. If important context falls outside this window, the model might generate irrelevant or incorrect content.
Inherent uncertainties. Language can be ambiguous, and sometimes the model must guess the user’s intent or the meaning of certain phrases. This can lead to hallucinations where the model fills gaps with incorrect or nonsensical information.
Training data constraints. The quality and diversity of the training data significantly impact the model’s performance. If the training data has biases, inaccuracies, or lacks certain information, this can lead to hallucinatory outputs.
Complexity of tasks. More complex tasks, such as answering detailed technical questions or understanding nuanced human emotions, are more challenging for the model and can lead to higher rates of hallucination.
Thus GPT hallucination is a limitation of current AI language models, reflecting the challenges in dealing with the vast and intricate nature of human language and knowledge. It’s an area of ongoing research and development in the field of artificial intelligence.
Now the situation is clear. A LATEX query uses the vast data set of LATEX pages on the internet, in books and articles with no biases or inaccuracies. Therefore, there are no hallucinations I could find, except in programming.
To help you to gain such benefits from ChatGPT, I decided to write this article.
2 What is ChatGPT?
Let us ask ChatGPT:
What is ChatGPT?
And here is the answer (edited for length):
ChatGPT is specifically designed to generate human-like text in a conversational context, based on a deep learning architecture known as transformers. The key characteristics and functionalities of ChatGPT include:
Conversational AI. ChatGPT is fine-tuned for dialogue, making it adept at understanding and generating text in a conversational format. It’s capable of maintaining context over a series of message exchanges, allowing for more coherent and relevant interactions.
Large scale language model. ChatGPT is trained on a vast corpus of text data. This training enables it to generate text that’s often coherent, contextually relevant, and surprisingly human-like.
Versatility. It can perform a wide range of language tasks, including answering questions, providing explanations, engaging in casual chit-chat, creative writing, summarizing texts, translation, and more.
Contextual understanding. ChatGPT can understand and recall information from the current conversation, allowing it to provide more relevant and continuous responses. However, it does not have access to external databases or the internet for real-time information, and its knowledge is limited to what it learned during training, up to its last update.
It is remarkably easy to start using ChatGPT. Go to OpenAI.com, scroll down, and click on:
Now2Or you can simply load ChatGPT directly from https://chatgpt.com. at the bottom of the new page, you see:
Type your prompt, click the up arrow. That is it.
3 What it cannot do
It should now be clear that we should ask ChatGPT questions that require the large amount of data it has acquired to answer. Otherwise, you may really get ‘nonsensical and fabricated content.’
Donald Knuth3The creator of TEX. illustrates this:4https://www-cs-faculty.stanford.edu/~knuth/chatGPT20.txt “Since one of today’s popular recreations is to play with ChatGPT, I decided on 07 April 2023 to try my own little experiment.”
Knuth’s first question:
Tell me what Donald Knuth says to Stephen Wolfram about ChatGPT.
Clearly, the answer will not be useful. There is no large, relevant data set. You are asking the shepherd in New Zealand about elephants.
His tenth question is better:
How many chapters are in The Haj by Leon Uris?
ChatGPT responds, in part:
“The Haj” by Leon Uris is divided into three parts.
This is incorrect, it is divided into five parts. (Knuth thinks it is divided into four parts. One better than ChatGPT but still wrong.)
I asked ChatGPT:
Be an expert on 20th-century novels. How many parts are in ‘‘The Haj’’ by Leon Uris?
And the answer is:
As of my last update in April 2023, I do not have the specific titles of the parts in “The Haj” by Leon Uris. For the most accurate and detailed information, including the titles of the parts, I recommend referring to a physical copy.
4 Asking good questions
How do we ask good questions that elicit useful answers? Let us ask ChatGPT.
How do we ask effective questions?
Here is the answer (edited for length):
Asking good questions is a crucial skill that can lead to more informative and useful answers. Here are some tips for asking effective questions:
Be clear and concise. Aim for clarity in your questions, and avoid overly complex or convoluted phrasing. A clear, direct question is more likely to receive a clear, direct answer.
Be specific. General questions can lead to vague answers; specific questions help in receiving detailed and relevant information. For example, instead of asking “How can I improve my health?,” ask “What are some effective low-impact exercises for improving cardiovascular health?”
Provide context. Giving context helps the person you’re asking understand your question better. For instance, if you’re asking for advice on a project, briefly explain what the project is about.
Know your objective. Understand what you want to achieve with your question. Are you looking for facts, opinions, advice, or something else? Tailor your question accordingly.
Open-ended vs. closed-ended questions. Use open-ended questions (those that can’t be answered with a simple ‘yes’ or ‘no’) to encourage a detailed response; use closed-ended questions when you need specific information or a concise answer.
Prioritize your questions. If you have multiple questions, prioritize them. Ask the most important ones first, especially in situations where you might have limited time.
Follow-up questions. Be prepared to ask follow-up questions if the response you get isn’t clear or if it leads to more queries.
There are several more key considerations for asking effective questions (if you want to charge a lot, call this ‘prompt engineering’).
Specify the field of inquiry. For instance, as demonstrated in Section 3, we initiated the question with
Be an expert on 20th-century novels.
Since our focus is solely on LATEX, you should always begin every session with
Be an expert on LaTeX.
Typing latex is sufficient. GPT will remember the instruction.
Asking ChatGPT a question is just the beginning of a conversation. For example, ask:
Define \bmatrix
and after the long answer, respond
more examples
ChatGPT will then provide several additional examples.
Next, respond with:
All examples should be at least 4 x 4 matrices.
and now all examples are 44!
Let us think step by step. This is really amazing. Ask:
Define \bmatrix, let’s think step by step.
It will teach you the use of the \bmatrix command in seven steps, so easy to understand.
To show you the responses would require several pages. Type these commands and see the responses of ChatGPT.
5 The GPT Store
Let OpenAI tell you what the GPT Store is (edited for length).5http://openai.com/blog/introducing-the-gpt-store
Users have already created over 3 million custom versions of ChatGPT. We’re starting to roll out the GPT Store to ChatGPT Plus users, so you can find useful and popular GPTs. Visit chat.openai.com/gpts to explore. The store features a diverse range of GPTs developed by our partners and the community. Browse popular and trending GPTs on the community leaderboard, with categories like DALL·E, writing, research, programming, education, and lifestyle.There are featured GPTs every week.We will also highlight useful and impactful GPTs. Some of our first featured GPTs include:
Expand your coding skills with Khan Academy’s Code Tutor.
Design presentations or social posts with Canvas.
Find your next read with Books.
Learn math and science anytime, anywhere with the CK-12 Flexi AI tutor.
We call the items in the store special-purpose GPTs (GPT SPs).
The store also has top picks in seven categories; we select only two categories to discuss, Writing and Programming.
To get to the special-purpose GPTs, go to ChatGPT and click on Explore GPTs.
6 Style and grammar
In the Writing category, we find twelve items, most of them help to improve your writing. Here is a typical editing dialogue with the Creative Writing Coach. We ask for help—observe that the prompt asks “list changes by sentence, give reasons for change”; this is very important:
Edit for grammar and style, list changes by sentence, give reasons for change, ignore correct sentences: A~typical English grammar book ranges from 400 to 1860 pages in length (the runner-up is 1779). These are general books not particularly useful for math. I think few mathematicians would want to spend time reading any of them. So this book is not trying to teach grammar, but it does utilize some terminology. What we aim to do is simple and modest: select a few easy topics for discussion. If you follow our recommendations, you will eliminate 80% of your errors, making your papers easier to read and understand. Note: 80%! Achieving 100% would require 600 pages! I suggest reading a topic a day. Its just a few minutes of easy reading. Have fun.
Now the reply.
Corrected version with changes listed by sentence: Original: These are general books not particularly useful for math. Correction: These are general books that are not particularly useful for math. Reason: Added ”that are” to clarify the relationship between ”general books” and ”not particularly useful for math.” Original: So this book is not trying to teach grammar, but it does utilize some terminology. Correction: This book is not trying to teach grammar, but it does utilize some terminology. Reason: Removed ”So” at the beginning for a stronger, more direct statement. Original: What we aim to do is simple and modest: select a few easy topics for discussion. Correction: Our aim is simple and modest: to select a few easy topics for discussion. Reason: Simplified the structure for clarity and conciseness. Original: Note: 80%! Achieving 100% would require 600 pages! Correction: Note: 80%! Achieving 100% would require 600 pages! Reason: No change needed; the sentence is clear and effective as is. Original: I suggest reading a topic a day. Correction: I suggest reading one topic a day. Reason: Changed ”a topic” to ”one topic” for consistency and clarity. Original: It’s just a few minutes of easy reading. Correction: It’s just a few minutes of easy reading. Reason: Replaced the curly apostrophe with a straight one for consistency.
Much improved! This is really ChatGPT on steroids.
7 TEX programming
In the Programming category, there are a number of GPT SPs that do programming. We pick three: Code Copilot (Code Smarter, Build Faster), Grimoire (Code Wizard, Programming Copilot), and Code Guru (reviews code and comments existing code).
We ask them for help to code a command \threejump, inspired by the command \cleardoublepage:
Create a LaTeX command named \verb|\threejump| that will add \verb|\newpage| commands until the page number is divisible by 3.
7.1 Code Copilot
\documentclass{article} \makeatletter \newcommand{\threejump}{% \ifnum\numexpr\thepage\relax % Check if page number is divisible by 3 \ifnum\numexpr\thepage\relax<3\relax\newpage\fi \ifnum\numexpr\thepage\relax=3\relax\else% \ifnum\numexpr\thepage\relax>3\relax% \ifnum\numexpr\thepage\relax<6\relax% \ifnum\numexpr\thepage\relax=6\relax\else \ifnum\numexpr\thepage\relax>6\relax% \ifnum\numexpr\thepage\relax<9\relax% \newpage% \else\newpage% \newpage% \fi% \fi% \fi% \fi% \fi% \fi% \else% \newpage% \fi% } \makeatother \begin{document} \section{First Section} Some text here. \threejump \section{Second Section} Some more text here. \threejump \section{Third Section} Even more text here. \threejump \end{document}
It does not compile. The relevant part of the log file:
./threejump.tex:33: Missing number, treated as zero. <to be read again> \relax l.33 \threejump ? ax l.33 \threejump
7.2 Grimoire
\documentclass{article} \usepackage{etoolbox} \newcommand{\threejump}{% \whileboondvi{\numexpr\thepage\relax\mod 3\relax > 0}% {\newpage}% } \begin{document} % Example content to test the \threejump command Page 1 \newpage Page 2 \newpage Page 3 \newpage Page 4 \threejump Page 7 % This should be on a new page that is % divisible by 3 \end{document}
This is much more elegant, but does not typeset either. The log file:
l.63 \threejump ./threejump.tex:63: You can’t use ‘\numexpr’ in horizontal mode. \threejump ->\whileboondvi {\numexpr \thepage \relax \mod 3\relax > 0}{\newp... l.63 \threejump ?
7.3 Code Guru
\documentclass{article} % Define the \threejump command \newcommand{\threejump}{% \newpage \ifnum\numexpr\value{page}\relax\mod 3\ne 0 \expandafter\threejump \fi } \begin{document} % Sample content to demonstrate \threejump command \section{Section 1} Some content on the first page. \threejump \section{Section 2} Some content on a page number divisible by 3. \end{document}
This may be the most elegant code, using recursion. Unfortunately, this does not compile either. Here is the relevant part of the log file:
! Undefined control sequence. \threejump ...m \numexpr \value {page}\relax \mod 3\ne 0 \expandafter \three... l.18 \threejump ?
7.4 Testing
As indicated by the log files, unfortunately, none of these three codes compile. Chalk this up to early days. When they will compile, this will open up a really easy way to be exposed to TEX programming.
8 Hallucinating on steroids
Every week, OpenAI features four GPT SPs. In the second week after the opening of the GPT Store, it selected the GPT SP, Consensus. The next week, it listed Consensus as ‘Trending’ (one of six). Consensus is “Your AI Research Assistant. Search 200M academic papers from Consensus, get science-based answers, and draft content with accurate citations.”
So immediately, I dreamed about lists of publications with research summaries! This would be much more useful than the list of publications we usually get.
Be a lattice theory expert. List of publications of George Grätzer.
The search for publications specifically authored by George Grätzer yielded a limited number of results. Here are some of his publications:
“Joint Review of General Lattice Theory (Second Edition) and the Congruences of a Finite Lattice: A Proof-by Picture Approach” (2007) by G. Grätzer: This is an exposition by Grätzer presenting major results on congruence lattices of finite lattices and featuring his Proof-by-Picture method (Grätzer, 2007).
“Math into LaTeX: An Introduction to LaTeX and AMS-LaTeX” (1995) by G. Grätzer: This book provides an introduction to LaTeX and AMS-LaTeX, including detailed proofs that can be followed step-by-step, making it a practical reference for researchers (Grätzer, 1995).
“The Congruences of a Finite Lattice” (2005) by G. Grätzer: An exposition by Grätzer on congruence lattices of finite lattices, featuring his Proof-by-Picture method (Grätzer, 2005).
“The Mathematics of G. Grätzer and E.T. Schmidt” (2008) by G. Czédli: This paper discusses over 300 publications of George Grätzer and E. Tamás Schmidt, focusing on their lattice theoretic results (Czédli, 2008).
These publications highlight George Grätzer’s contributions to the field of lattice theory and his work on LaTeX.
For the record, the list has the first edition of my book The Congruences of a Finite Lattice, 2005, and it does not have the second edition, 2016, or the third, 2023. The third edition lists well over 100 of my publications in this field. References 1 and 4 are articles about me, not by me. Reference 2 is not math. Reference 3 is two editions too early. Only one out of four of the references provided is correct, and it is missing about three hundred. Not a very reliable performance.
9 Tokens, darn it
Life would be easier without tokens. But we need them: ChatGPT uses them to measure the size of your prompts and answers and restricts them to 4,096 tokens for ChatGPT 3.5 and twice as many for ChatGPT 4.0. Note that 4,096 tokens is roughly equivalent to six to eight pages of text.
To live within the token limits, draft clear and concise prompts. Write specific prompts to maximize your ChatGPT token allowance, especially if you want a more detailed response. Help ChatGPT avoid generating excessively long responses. For example,
What are the top five major tools to solve differential equations? Be concise and use bullet points.
Sometimes, you may need to provide specific details or elaborate on a query, which can use up more of your tokens. For instance, if you need to summarize a long meeting transcript, consider copying only the essential parts of the discussion. Use this prompt:
Summarize the main decisions in this conversation.
As a concrete example, if I upload this article and ask ChatGPT to proofread it, then it reads only two pages:
Note: I stopped here to avoid exceeding the token limit.
10 ChatGPT’s review
I wrote an article for the Journal of the European Mathematical Union on ChatGPT. Would like to get your comments.
Your article, titled “ChatGPT 101 for LaTeX Users,” provides a comprehensive overview of how ChatGPT can assist LaTeX users. You begin by sharing your experience of updating your book More Math into LaTeX and how discovering ChatGPT made this process more efficient. The article demonstrates the practical uses of ChatGPT in LaTeX, such as understanding LaTeX commands and dealing with errors. You also address the limitations of ChatGPT, including its tendency to generate ‘hallucinations’ or incorrect responses under certain conditions. This is followed by advice on how to ask effective questions to get the most out of ChatGPT, emphasizing clarity, specificity, and context. The article further explores the capabilities of ChatGPT in the context of LaTeX programming and editing for style and grammar. It concludes with reflections on the broader implications of ChatGPT and similar models in the field of artificial intelligence and their potential for revolutionizing various aspects of academic and technical work. Overall, your article is thorough, well-structured, and provides valuable insights into the interaction between ChatGPT and LaTeX, especially for those in the academic and research communities.
11 Mid-June 2024 update
I wrote this article around the Ides of March 2024. I am now revising and updating it for publication. I had to make a number of changes. In Section 2, I wrote:
“To start using ChatGPT is remarkably easy. Go to Openai.org.”
But there is no OpenAI.org. How disheartening. Would this stop you from reading this article as a result?
Of course, OpenAI.com is correct. Had to make a change.
Some other changes were more profound; for instance, the organization of the GPT store.
The most important change: earlier, free access was given to ChatGPT 3.5, while subscribers got ChatGPT 4.0 and the GPT store. Today, everybody gets ChatGPT-4o (‘o’ is for optimized) and has access to the GPT store. But do subscribe! If you do not, access is very limited.
12 The perfect storm
I am very careful about backups. But a perfect storm of hardware problems with my computer and its external hard disk had deleted this article, so I had to ask my editor to send me the PDF version I submitted.
When I received it, I had to figure out how to get a TEX version without having to retype it. The traditional way is to open the PDF file, export it as an RTF file, and use an RTF to TeX converter (free or professional). Sometimes this gives an acceptable result, although most of the time it produces a LATEX file that typesets into a PDF file that looks very similar, but the LATEX code is almost useless.
Then I had a eureka moment: why not assign the task to ChatGPT? I did, and it produced an excellent LATEX file.
The moral of the story: whatever your question or job, think of ChatGPT.
13 Conclusions
ChatGPT and the GPT SPs deserve a thorough study. Amazon’s Kindle Store lists hundreds of books, including ChatGPT MASTERY, ChatGPT for Dummies, and The ChatGPT Millionaire. Even ‘prompt engineering’ has hundreds of listings. Udemy offers thousands of ChatGPT video courses; prompt engineering has hundreds.
Fortunately for us, by focusing on LATEX, our needs are limited. For instance, the Udemy course ChatGPT Complete Guide has 17 chapters on prompt engineering, but only a tiny chapter is relevant to us.
I hope I have succeeded in getting you started.
In digital streams,
Wisdom flows through ChatGPT,
Guiding thoughts to light.
Future bright and clear,
Free from illusions’ shadow,
Hope’s horizon near.
- 1
Another time, the response may differ.
- 2
Or you can simply load ChatGPT directly from https://chatgpt.com.
- 3
The creator of TEX.
- 4
- 5
References
- G. Grätzer, More math into LATEX. (5th edition) Springer, New York (2016)
- G. Grätzer, The gods smile at me: The LATEXcompanion, third edition, and ChatGPT. TUGBoat 44, 319–321 (2023)
- G. Grätzer, Text and math into LATEX. (6th edition) Springer, New York (2024)
Cite this article
George Grätzer, ChatGPT 101 for LATEX users. Eur. Math. Soc. Mag. 134 (2024), pp. 32–39
DOI 10.4171/MAG/207