Перейти к содержимому

Undefined control sequence latex что это

  • автор:

Errors and warnings

If LaTeX runs into code it doesn’t understand it will stop typesetting and will give information about the error. It can also output warnings.

Errors

If TeXworks encounters an error it will show a message in the console and wait. Such a message looks like

It starts with an exclamation mark and a description of the error ( Undefined control sequence ), followed by the line number ( 6 ) and the command where the error occured ( \authr ). Watch out: the line number that is displayed doesn’t have to be the location where the error in your code was made. For example, if you forget a > then LaTeX will probably find out at the end of a paragraph. When an error is encountered you can stop typesetting and fix it. Alternatively, there are ways to surpress errors, but we recommend that you always fix your errors. If you don’t do this, it is possible that the errors stack up and the output is not as desired.

We will now discuss some errors that occur very often.

Too many >’s
Undefined control sequence

An unknown command was used, here \dtae , which should have been \date .

Missing $ inserted

A math command was used in text mode, in this case \alpha .

Runaway argument

In this example we forgot the > belonging to the \date command.

Missing package

Here we misspelled babel . It could also happen that the name is correct but the package is not installed yet. Packages can be installed with the TeX Live Utility if you’re using TeX Live. You can also put the .sty file of the package (download it from CTAN) in the folder of your .tex file.

\begin ended by \end.

LaTeX found a \begin without an \end . This is a typical example of a mistake which is discovered very late (the mistake somewhere around line 20 is discovered at line 127).

Package babel Error: You haven’t loaded the language dutch yet.

This happens when one changes the language in the babel package. The solution is to delete the .aux file. In TeXworks this can be done by File -> Remove Aux Files . (If you get an error about permissions when doing this, you have to make sure to work in one of your own folders and not in a temporary folder. Moving your .tex file will solve your problem.)

Warnings

Sometimes LaTeX gives warnings. For example if you use \maketitle but never inserted an author it will display:

LaTeX won’t stop typesetting after a warning. To see a list of warnings in TeXworks go to Window -> Show Console Output .

Overfull hbox

This warning indicates that a word does not fit on a line correctly. This happens when LaTeX doesn’t know how to break a word or because there is a long line in math mode in a sentence. It can be solved by adding \- to words, as discussed previously. If nothing works you can add \\ to break a line manually but this only should be done when the entire text is finished. The converse of an overfull box is an underfull box.

Solving errors

We conclude with a few general tips on how to solve errors.

Find the problem by commenting out text temporarily

Often you don’t know what exactly causes the error. To discover the cause it can be useful to turn off parts of your code using % . In TeXworks you can also click Format -> Comment . If the code runs afterwards, the mistake has to be in the part which you commented out.

Delete auxillary files

Sometimes an error is caused by auxillary files. If you cannot explain an error, try deleting these files. In TeXworks this can be done with File -> Remove Aux Files .

Typeset regularly

It is considered a good habit to typeset your document after typing a few new sentences. If you typeset after 100 lines it can be hard to trace back your errors. Once you get more familiar with writing .tex documents you can reduce this, e.g. typeset only once a paragraph is finished.

Exercise

Fix all mistakes in the Dutch article below. Let one of your teachers check your solution.

Undefined control sequence

This error appears when L a T e X does not understand one of the commands you have used.

Common Examples

Typo in a command:

The most common causes of such an error are simple typos. An example of such a typo is shown below, where you accidentally pressed Z instead of a when writing \alpha

This will give an error message of

main.tex, line 10

Undefined control sequence.

<<recently read> \Zlpha l.10 A typo when writing $\alpha$ could be $\Zlpha $ The control sequence at the end of the top line of your error message was never \def’ed. If you have misspelled it (e.g., `\hobx’), type `I’ and the correct spelling (e.g., `I\hbox’). Otherwise just continue, and I’ll forget about whatever was undefined. [1

These errors are easily spotted by humans but can cause LaTeX to get confused as to what is being asked.

Forgetting to load a package:

Another cause of such an error is when a specific package is needed to use a certain command, but it is accidentally forgotten in the preamble. An example of this would be

In this example, the document will fail to compile as L a T e X doesn’t recognize the \xspace command. This is not a typo, as \xspace is a perfectly fine command. The problem is that you have forgotten to include \usepackage in the preamble. When this line is included, the error message will disappear as LaTeX now knows how to interpret the \xspace command.

Backslash used in wrong place:

Another cause of an Undefined Control Sequence error is a backslash used inappropriately. This can happen particularly when writing file links as shown below.

The issue is that when LaTeX sees a backslash \ , it interprets what follows as a command. Here, there is no such command as \Users, so you will get an Undefined Control Sequence error. To avoid this, when writing text you should write a backslash as \backslash . For writing long file paths and urls, it may sometimes be more convenient to use the url package rather than writing \backslash every time.

How to fix LaTeX \glqq or \grqq error ‘Undefined control sequence’

but when you try to compile it, you see an error message like this:

Solution:

In order to use \glqq or \grqq you need to include

after your \documentclass declaration.

In case you want to use another language, use the correct language specifier instead of ngerman .

If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow

Ошибка в LaTex ! Undefined control sequence.

При компиляции выдает ошибку: ! Undefined control sequence. \DeclareUnicodeCharacter и так ругается на все строки ниже. На других компьютерах собирает файл нормально. Помогите исправить, пожалуйста. В LaTex 2й день, так что подробно.

\usepackage[english,russian] \usepackage \usepackage

\usepackage[pdftex] \usepackage \usepackage \usepackage \usepackage \usepackage \linespread <1.3>\pagestyle \usepackage

(государственный университет) \flqq МФТИ\frqq\\

Факультет \\ Кафедра \\ \end

Какая кодировка у самого текста? UTF-8? В смысле unicode?

Наводящий вопрос: Какой операционной системой пользуешься? В каком редакторе текст набираешь?

Кодировка \usepackage[cp1251]. Система Win7, набираю в редакторе Texmaker, далее компилирую в PDFLaTex/

Смущает то, что это свежая система и только загруженный тех, а он не попросил не единой дозагрузки файла. Возможно в этом дело.

А точно cp1251? Я не очень в курсе какое там в win7 сейчас тысячелетие, что до сих пор используется 8ми битная кодировка, но по моим воспоминаниям Texmaker по умолчанию вроде как utf-8 предполагает.

То, что было в посте собирается без проблем (я поменял cp1251 на utf-8). Естественно нужно добавить \end и \end, которые почему-то выпущены.

Не очень понимаю что значит дозагрузка файла. Если не очень разбираетесь, то лучше ставить сразу _весь_ дистрибутив чтобы не нужны были никакие дозагрузки.

Я о дозагрузке пакетов при первом запуске

Before compiling your first document, you must set the encoding used by the editor («Configure Texmaker» -> «Editor» -> «Editor Font Encoding»).

Убедитесь, что там выставлена та же кодировка, что и в теле документа.

я поменяла кодировку на utf-8 и у меня появилась теперь такая ошибка ! LaTeX Error: File `utf-8.def’ not found.Type X to quit or <RETURN> to proceed,or enter new name. (Default extension: def)Enter file name:! Emergency stop.<read > \endinput

. А зачем? Такое ощущение, что вы устанавливаете что-то очень и очень странное. Всё должно лежать у вас на диске.

Извиняюсь. Поставьте utf8 (без тире).

Если без тире, то вот что выдает ! Missing ) inserted for expression.<to be read again>( ��

Давайте файл целиком. А лучше пройдите указанный мной выше тьюториал.

Я закомментировал только вставку картинок, потому что их не было.

Текст имеет кодировку cp1251, так что поменяйте utf8 обратно на то, что было.

Проблема скорее всего в том, что и как вы на win7 установили. Тут к сожалению мои телепатические способности отказывают. Могу только посоветовать прибить то, что у вас сейчас там стоит и поставить современный дистрибутив полностью (не жадничать с местом), например TeX Live: https://tug.org/texlive/acquire-netinstall.html

Возможно вам удастся настроить то, что у вас есть сейчас, но как это сделать я не знаю, так как в моём случае установка начиналась и заканчивалась, как правило, командой

Спасибо, буду пробовать

Удалите, пожалуйста, pdf файл чтобы у меня его антиплагиат не нашел потом

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *