I'm having serious problems understanding the syntax of LaTeX well. I know a lot of programming languages but LaTeX still is a little cryptic for me. Do you know what the key to fully understanding it is?
[Tex/LaTex] The key to understanding the LaTeX syntax
latex-miscsyntax
Related Solutions
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).
However, you mention a couple of specifics so let me try to answer them. {} are lexical:
\def\hello{world}
{\def\hello{hello}
\hello}
\hello
produces: "hello world".
The grouping given by square brackets is an illusion. Some commands in LaTeX start with "If the next character is [, gobble the rest up to ] and use it as the first argument.". This can cause problems if, for example, what you want to pass has a square bracket in it:
\newcommand{\hello}[2][hello]{#1 #2}
\hello{world}
\hello[greetings]{world}
\hello[Greetings [1] to the]{world}
Produces
hello world
greetings world
Greetings [1 worldo the]world
because the first argument to "hello" in the last line is "Greetings [1".
(This can be remedied by using braces to do proper grouping, \hello[{Greetings [1] to the}]{world}
would work fine).
I've never heard of commas being special. Can you give an example?
Only way to learn latex is to Start using it -- Practical first and reading next
You need not know any programming language. What you need is -- Strong will to use latex, a latex-aware editor (since it will save you from switching to command prompt often), a tex distribution installed and tex.stackexchange.com
;-)
Source code
What you find below is called source code -- it is what you write:
\documentclass{article}
%% This place is called the preamble
\begin{document}
Hello world
\end{document}
You have to save the above code as some file (say mycode.tex
). BTW you have to edit/write this code in an editor that is latex aware - like texmaker, texniccenter, texstudio, Vim, winedt (windows only, shareware), Inlage (windows only, not free) to name a few. Now you need to have a Tex distribution to compile the above code - Famous ones are texlive 2012 (multi platform) and miktex (windows only). You may google to find out from where to download ;-)
. Say you downloaded texlive 2012 and installed it. Now there are two ways to compile the code:
Go to the command prompt. Navigate to the folder where you have kept
mycode.tex
by typing something likecd c:\my folder
. Then typepdflatex mycode
Then the source code will be compiled and a pdf file namedmycode.pdf
will be generated in the same folder. This pdf is the output.Or
The editor will have a toolbar button (that is why we call it latex aware). Just click that button and you will be saved from using the command prompt. (trust me, I am also afraid of command prompt, Please keep it a secret
;-)
)
Additionally in tex/latex, there is a package for every need. Say you want to play with the page magins (layout), then geometry
package, if you want to insert a figure, then the graphicx
package, so on and so forth. They can be loaded using \usepackage{<package name>}
. And how to use those packages? You will find the details in the documentation of respective packages. To access them, you can type texdoc <package name>
(for example texdoc geometry
) from the command prompt, or the editor you are using will provide some (help) menu item for the purpose. Clicking it, will open a dialogue window where you can type the package name and proceed.
And please don't get intimidated by (some of) the technical documentations. There are well written (I mean easy to follow) manuals too, for example, check the pgfmanual
. In case if some thing troubles you a lot and you can't get rid of it by yourself, please post a question here. This site has expertise equivalent to years of reading the documentation and people here are very friendly, helping and very kind hearted.
Hope this will be useful. I wish you less troublesome start and happy texing.
Best Answer
Since LaTeX builts on TeX, a very good foundation to understand its syntax is learning the TeX syntax. Here are helpful documents (I took it from a list on my blog):
Specifically for LaTeX syntax, there's a huge amount of documentation and there are many books and online tutorials and introductions. For understanding what the LaTeX author Leslie Lamport meant with LaTeX syntax extensions, I recommend to read his book "LaTeX: A Document Preparation System".