Tag Info

Hot answers tagged

78

\( ... \) 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.


72

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 ...


51

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 ...


38

\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 ...


37

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.


35

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 ...


34

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.


33

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 ...


32

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 ...


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 ...


30

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 ...


29

$$ 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 ...


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

$$ 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 oder align. If you use equation you sometimes get some strange spacings.


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). ...


26

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 ...


25

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, ...


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 ...


22

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 ...


21

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 ...


21

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 % ...


18

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 ...


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} ...


16

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 ...


15

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 $.


14

End each line with a %. This will gobble the line-feed and all whitespace at the beginning of next line. Thus you'd get \documentclass[option1,% option2,% option3,% option4,% option5,% option6,% option7]{article} to do what you want it to. Edited To Add: As ...


14

Another way to do this kind of thing is to use a \lccode trick: \begingroup\lccode`!=`\\\lowercase{\endgroup\def\@backslashchar{!}} This avoids any need to change catcodes thanks to the special properties of \lowercase. Compared to the \expandafter\@gobble\string method, it's a bit more flexible as you can choose the catcode of the resulting character ...


14

You need a very recent expl3 (January 8th, 2011) for the following code to work (I added \ior_str_map_inline:nn a few minutes ago). \RequirePackage{expl3,l3str} \ExplSyntaxOn \bool_new:N \g_strange_tmp_bool \tl_new:N \g_strange_last_line_tl \tl_new:N \g_strange_line_tl \int_new:N \g_strange_indentation_int \int_new:N \g_strange_last_indentation_int ...


14

You can use a combination of \stackrel and \mathclap (from the mathtools package): \documentclass{article} \usepackage{mathtools} \newcommand\myeq{\stackrel{\mathclap{\normalfont\mbox{def}}}{=}} \begin{document} \begin{align*} a &\myeq b \\ &=c \\ &= d. \end{align*} \end{document} If using mathtools is not an option, you can use a ...


14

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 ...



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