Tag Info

Hot answers tagged

98

The short answer is what others have said, % starts a comment that goes to the end of the line. The normal effect is that it doesn't insert the space (or a \par) from the newline. The longer answer is that as TeX parses its input, it reads the input file line by line. It strips off tailing whitespace (including any carriage return and newline) and then ...


93

\( ... \) is LaTeX syntax. $ ... $ is TeX syntax. plainTeX only allows $. In LaTeX you can use both, but \( ... \) will give less obscure error messages when there is a mistake inside it. Both are shortcuts to start inline math environments.


77

Here is one more reason (this is what converted me). If you use the \begin{proof}...\end{proof} environment, you occasionally end a proof with an equation. The automatic QED box then ends up on a line by itself, which is ugly. You can fix this by writing \qedhere at the end of the equation, but this doesn't work properly with $$...$$ – you have to use ...


61

$$ is TeX primitive syntax, which, as others have commented is hard to redefine (in classic TeX there is no command name which triggers entering or leaving display math). LaTeX doesn't officially support $$. The most noticeable failure if you use the syntax is that the fleqn option will no longer affect the display of the mathematics, it will remain ...


45

\par is a Tex primitive and is the same as a blank line (except in special environments such as verbatim where the usual rules don't apply). It ends horizontal mode, causes TeX to break the horizontal text into lines placed on the current vertical list, and exercises the page breaker which may possibly cause the next page to be shipped out. \\ is different ...


42

While listings package is good, it has some deficiencies, especially in Unicode support. I'd recommend trying out minted, which uses the output of Pygments, which is more likely to get grammar updates than listings.


41

The short answer is you use \verb where you need to write a small piece of inline verbatim material that contains characters TeX treats (or rather, is currently treating) as special. \texttt is for when you just want typewriter font. \verb has some downsides, such as not working in moving arguments. In those cases, you're probably better off using \texttt ...


40

Anyone who's ever tried writing a simple perl (or whatever) script to quickly parse a LaTeX document and do something in maths mode but not in text mode will agree that \( .. \) is the only way to go! Trying to get the pattern matching right against $a^2 + b^2$$c^2 + d^2$ is a nightmare. (Before anyone asks, yes I have, and it's called mathgrep. The pain ...


39

General tips Use as few packages as possible, Call the packages in particular order, Use many small documents instead of one big one, Comment your code, Write readable code, Concentrate on the content, not on the appearance. General tips somewhat explained That's because packages tend to conflict and go obsolete. (See How to keep up with packages and ...


38

The standard way of doing this is to use the listings package. It allows a wide range of formatting for the output, can choose to display only part of an input file and so on. The package also comes with a number of predefined languages it understands, including Python.


35

The tilde ~ is an unbreakable space, i.e. the line will never be broken at this position. If you write Table~\ref{...} the table number generated by \ref will always be on the same line as Table, which is the preferable formatting. Having "Table" at the end of a line and then "1" at the beginning of the next simply looks bad. The tilde is also used in names ...


31

There is a standard. It's a matter of opinion whether it's sensible or not, but it's been there since the release of LaTeX2e. Font aspect changing commands have two forms: action and declaration The same holds for abstract instruction such as "emphasize" Size changing commands have only the declarative form. Let me review the three points. Font aspect ...


31

I think things are just a bit more complicated than in @Joseph's answer. (Though in laying them out, I may violate the desire for a "concise" answer.) My go to reference for details of the BibTeX format is Norman Walsh's page which self describes as: This help entry contains the same information as Appendix B of the LaTeX manual. In BibTeX's world ...


29

$$ is plain TeX and could have some side effects, also fleqn will not work anymore. Please have a look at l2tabu. In my opinion the best environment for equations is gather or align. If you use equation you sometimes get some strange spacings.


28

LaTeX's optional arguments viz TeX's macro arguments (delimited and undelimited) The LaTeX concept of optional arguments (i.e., arguments that may or may not been used) is a concept that is not directly supported by TeX's parsing and execution. TeX macros always expect the same number of arguments with the same syntax for delimiting the argument. Optional ...


27

Loading the strict package prevents using LaTeX's declarations as environments. Loading the fixltx2e package fixes some LaTeX2e errors. fixmath changes LaTeX's default math style to comply with some international standards, specifically regarding Greek letters, see package description. There are many packages improving LaTeX's standard behavior, for example ...


26

You need to give the 'sub-language' for TeX: language = [LaTeX]{TeX} As you are writing a package, you might also want to use the moretexcs key to add 'new' LaTeX commands. For example, in my siunitx I have very long list: moretexcs = { addto, ampere, ang, angstrom, ... to cover all of the new macros it adds, ...


26

For a programmer, I would recommend reading the book "TeX by Topic" (available for free at http://www.eijkhout.net/tbt/). I think that that will give you the best answer to your general questions (which really are, in my opinion, a bit too general for this site; I would advise you to read TbT and then ask more focussed questions on particular aspects). ...


24

Programing fixltx2e is essential etoolbox provides some functionality that one can only get from hacking LaTeX kernel or using the internal macros otherwise. Also it provides some useful document and environment hooks xspace is a tiny but useful macro for defining text oriented macros geometry, typearea, etc, use one and only one of them. The same ...


24

Good approach is defining new environments for programming language. Minimal setup can be around this: \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} % Default fixed font does not support bold face \DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold \DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12} % for normal % Custom colors ...


23

As @egreg has explained, partly it is the way it is because that's just how it is (and was in latex2.09 and plain tex). Apart from just being a syntax choice, there are also efficiency considerations. As a switch you can go \large at the beginning of a document and the whole document goes large (it is an assignment as if the syntax were ...


23

You already got lots of answers. You can also just experiment yourself: \documentclass{article} \begin{document} Hello% world! \end{document} Try compiling this with and without the %. Then you see yourself that the % makes the space produced by the newline disappear. (Note that you'll still get the space if you write Hello % with a space before the % ...


20

Suppose, purely for the sake of argument, that one were typesetting a book which had frequent occasion to reference publications by name --- Science, the New York Times and so forth. In a WYSYWYG editor, one would highlight the name of the journal and click the I button. With syntactic markup, like plain ol' HTML, one would wrap the journal name in codes ...


20

You are correct that it is not always easy to remember which is which1. There is no real reason behind it - except that an optional argument is by convention and is -- by now become an unwritten rule -- made up of square brackets. So if you know the argument is optional, in 99% of the cases you will be safe to use a square bracket. It is also the first ...


20

Historically there has been a lot of confusion over the two forms, (the situation with \phi and \varphi is similar but even more confused as at one point Unicode swapped the reference glyphs). I added a special section about epsilon to the XML/HTML entities spec http://www.w3.org/2003/entities/2007doc/#epsilon The situation in TeX is no different really, ...


19

There's no technical difference, as long as content is available/declared when they are used. That's because TeX is a macro language where macros and their arguments are substituted for a replacement text - the latter is only evaluated when used (unless evaluated at definition, like with \edef or \xdef). For example, looking at ...


18

Really a postscript to @Yiannis answer but the rule about the [] arguments being optional isn't unwritten it is explicit in the LaTeX Book that that is the LaTeX syntax. Using the primitive \def facilities it is possible to define commands with essentially arbitrary syntax but commands defined in all of the core LaTeX distribution and most contributed ...


18

Let's examine your example with care. \begin{figure}[h] You're starting a figure environment. Error: [h] should be [htp] or something. \centering You want to center everything. In particular, there's no indentation at the start of the paragraphs. \subfloat[]{\label{a} \includegraphics[width=0.5\textwidth]{a.jpg}} \subfloat[]{\label{b} ...


18

There are some good 'meta' reasons for using \( ... \) in some circumstances. Environments such as Fancy Verbatim and alltt will allow \( and \) to act as math mode, but $ will be interpreted as a literal. Another convenience is that some editors have an easier time with paren matching for \( ... \) than with $.


17

Semantic is defined as "Of or relating to meaning". Syntactic is defined as "described by grammatical structure." When expressions are simple, it's fairly easy to read either structure. When they're complex, it's much easier to read things which are defined by the meaning of their expressions rather than by the order of their symbols. \set{a, b, c} is ...



Only top voted, non community-wiki answers of a minimum length are eligible