2

Sorry for my silly question but I've always used latex from an editor and also with the most basic commands to write my math homework. Now that I need a few more resources to apply in my documents I thought of seriously start studying tex from the beginning and also learning how packages and classes work internally. So there's one of the instructions \show that is used accordingly to show the definition of a command in terms of primitive commands. I first though that this command was like any other in the sense that I can put it between the \begin{document} and \end{document} but when I compile the file, it doesn't do anything. Then I started looking up for the right way to use this command and apparently it works by using command lines in a terminal, which is a new concept for me. So what I'm asking is how to run latex by using commands (particularly on windows) and also if this is an alternative to using an editor or is used only for specific instructions. Also it would be great if you could point me into some manuals or books where I coud learn this.

  • 3
    LaTeX is run within a command line, always. The editor is jusst hiding it from you. \show will show you something, and halt the LaTeX run waiting for your input, which most editors won't allow and hence run in nonstopmode. If you want to know how LaTeX works, read some introduction and later texdoc source2e. – Johannes_B Apr 28 '15 at 16:08
  • 4
    You might want to think about your choice of editor: the more sensible ones show you the console output as your run TeX, so you will see \show and so forth. (TeXworks is a good example.) – Joseph Wright Apr 28 '15 at 16:08
  • BTW, we've had a similar question before: I'll try to track it down – Joseph Wright Apr 28 '15 at 16:09
  • @Johannes_B I think texdoc source2eitself is an example of the use of the command line. @Daniela Diaz It would be interesting to know which operating system you use. – Chaplin Apr 29 '15 at 19:08
  • 1
    Are you looking for \meaning <macroname>? If this is what you want, it helps to \usepackage[T1]{fontenc}, so that backslashes look like backslashes. – Steven B. Segletes Apr 30 '15 at 1:17
7

LaTeX is always run from the command line: An editor simply enters the command for you when you hit the button. Most tex editors will even allow you to customize what command you send.

Given this, you don't need to write your file on the command line. Simply write and save the file as normal. Then open a command line, and go to the directory you saved it to.

>cd C:\Terrible\Sample\Directory

or

>cd /usr/cthulhu/home/terrible/sample/directory 

for example. (Odd thing that makes no sense, if you need to change drives on windows, you have to type in the drive name. As in you can do cd D:\Terrible\Sample\Directory while you are on C: and nothing will seem to happen. Type D: and boom, you are in the right place on D. So just move drives first, and it is less confusing.) Another easy way to do this is open your tex file in notepad++. In the file menu it has an option Open Containing Folder that lets you pick Explorer or cmd. cmd while open the folder with your tex document on the command line for you.

Now you are in the right folder, this is just like opening the file in Explorer or a file manager. Now you need to run LaTeX. The exact commands you need to enter here depend on how complicated your file is. The most basic version to compile example.tex would be just >pdflatex example. After this runs you'll have example.pdf saved in the same folder. Now, if you need to run biber or bibtex after that, you do the same thing: >bibtex example, then run >pdflatex example again to update the pdf.

Of course, this will change depending on your tex engine: if you run latex instead of pdflatex you'll get a dvi, and you'll have to do something else if you use XeTeX or LuaTeX, but it should be similar.

Now, basic PDF? That is quite simple. However, suppose you have a table of contents, a works cited, and are using the lastpage package? You are going to have to compile a whole bunch of times, probably at least three. This is a pain, so there are packages to do this for you. I know of autolatex and latexmk. These compile your pdf, check if there is more work to be done, then run bibtex, compile again, whatever, for you, over and over until it is finished. Now, I've only used latexmk myself, though I've heard people say autolatex is better (I just don't want to install Python). To use it you just type >latexmk -pdf example and it will take care of everything for you. If you don't type the -pdf it will give you a dvi (You can fix that in the config file, but I've never figured out where to put that on Windows to do that globally. If you are on mac or *nix the manual will tell you that.)

Now, suppose you have an error or are using \show. Your document will start compiling, text will scroll down your screen (if you are on windows always type 'color 2' before starting, then it will look like The Matrix) and then it hits the error or \show and stops. It will then give you some options. I've never used \show, but if you hit an error it will give you two options I know of: x will kill the compilation now, and you can go fix the error, and r will tell it to try and compile anyway, which, if it can, will often let you see where the stupid $ you missed is, by making everything after it math mode (or similar.)

Does that all make sense? This is how I often compile my files, and I'm far more of an inexperienced user then most of the people here, so I'm hoping I was able to clarify things.

  • I've been looking for some book or manual that explain all of this but the thing is mostly they assume that you know how to do it and focus only on how to write latex. They never say how to implement it, or how to run the program, etc. So I wonder how you learned all this. – Daniela Diaz Apr 30 '15 at 1:03
  • @DanielaDiaz Well, I knew how the command line worked already, then I went to the wikibook (en.wikibooks.org/wiki/LaTeX) which is quite good and starts at a basic level. I recommend digging out a command line or MS-DOS introduction, reading the basics of that, then moving on to the wikibook. There are also a few really good threads on how to get started for beginners on here; I'd look them up. – Canageek Apr 30 '15 at 6:43
  • 2
    About the windows oddness you need the switch /d to change both the drive and the directory. So you need cd /d D:\foo\bar – percusse Apr 30 '15 at 7:04
  • @percusse Good to know. Typically I just forget then type d: after, but that would be useful in scripts. – Canageek May 1 '15 at 20:13
1

Like I said my question is very naive and silly for the experts but just for the record this is what I have till now. If you guys could help me complete this answer would be very helpful:

Command-line interface is just a different way of operate a system by using lines of code or commands instead of the usual graphical interface in which we use the mouse and click on icons etc. So even when the graphical interface works very nicely because it allows to work with many tasks at the same time there are some advanced tasks that may need to use the command line.

In my case I'm using Windows 7 and to work in the command-line interface I have to use the MS-DOS console (I open it by using the windows key + R and then writing cmd).

To deal with all that can be done there I just write help after the first line and a list of many commands appears on the screen. If I want to know how one of them in particular works, say the instruction copy, I can get it by writing copy /?.

In particular to know the definition of a latex command, say enumerate, I introduce in the console latex, then \relax, and finally \show\enumerate. This produce something like this:

enter image description here

Now, I still don't know how to create a .tex file from the command-line, save it in some directory and print it as a .pdf file. More importantly I don't even know where to get the tex instructions that I can introduce in the command-line. I've always done this by using the tex editor, in my case TexMaker, but I think it would be really nice to learn how to do it by using the console.

  • 2
    .tex files are just plain text files. You can create one in any editor - either a graphical editor on a command line one. On unixy systems, there are a bunch of such editors for the command line (e.g. vim, emacs, pico, nano...). Is there something similar for ms dos? You could write your files without an editor, at least on a unix-type system, but I don't know why you would want to do that as it would be a complete pain. To turn a file into a PDF, just say pdflatex <filename.tex>. – cfr Apr 30 '15 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.