LaTeX \cite giving a [?] - latex

in blah.tex , I have a
\cite{blah}
I have a 'blah' entry in blah.bib
I run my file with :
latex blah.tex && blah.tex && dvipdf blah.dvi
The blah.pdf results in [?]
How do I fix this?

You are missing a second latex:
latex blah.tex && latex blah.tex && dvipdf blah.dvi
------------------^
If you use BibTex (which you obviously do), you'll probably have to issue the command a third time (two times after applying bibtex blah):
latex blah.tex && \ # that's for preparing for bibtex
bibtex blah && \
latex blah.tex && \ # that's for resolving the crossrefs
latex blah.tex && \ # and that for putting them in the right place
dvipdf blah.dvi

You could also adopt latexmk and not have to think about all this process anymore :)
Just do
latexmk blah
and it will take care of compiling everything the correct number of times. It's bundled with any good TeX distribution, and you can get the manual with texdoc latexmk.

Latex does not look in your .bib file - it looks in your .bbl file. Have you run bibtex on your .bib file to generate your .bbl file? Is your 'blah' entry in your .bbl file? If not, run bibtex again.

Compile it for the second time, you're done. Otherwise, clear all the auxillary files bla.tex produces and recompile twice.

Related

How can I strip figures and table during a pandoc LaTeX to Word conversion?

I am trying to use pandoc to convert a thesis from latex to docx. In general, this works well with the following command:
pandoc input.tex -f latex -t docx -s -o output.docx --bibliography references.bib --csl=mystyle.csl
However, I have an additional requirement that I am unable to fulfill. I want the output to be stripped from any figures and tables that are included in the source files. Reading the pandoc documentation and related stackoverflow question has not helped me so far.
Do you have suggestions on what could do the trick?
This is a poster use-case for pandoc filters. The following Lua filter will delete all tables and images:
function Image () return {} end
function Table () return {} end
Save it to a file, say remove-tables-images.lua, and pass the file to pandoc via the --lua-filter parameter:
pandoc input.tex -s -o output.docx \
--bibliography references.bib --csl=mystyle.csl \
--lua-filter remove-tables-images.lua

Compile two versions of a document from the same latex source

How to automatically compile two versions of the same document, for example version without answers for the students and another version with answers for myself?
I have a small bash script to do a dual format.
function latex-ans () {
n=$(basename $1 .tex) # strip .tex in filename foo.tex -> foo
ln -s $n.tex $n-ans.tex # create a soft link (for instance foo-ans.tex -> foo.tex)
pdflatex '\def\withanswer{1} \input{'$n-ans'}' && pdflatex $n
% first format the version with answers and then the normal version
rm $n-ans.tex $n-ans.log
% remove useless files
}
If I have a file foo.tex, this commands formats both versions of the file and generates two pdf: foo.pdf and foo-ans.pdf. Thanks to the renaming of foo.tex through the ln -s, it also keeps separate foo.aux and foo-ans.aux to preserve useful information on both versions.
At the latex level, I basically do the same and use the macro \withanswers to configure my packages.
There are several packages that allow to conditionally exclude certain parts of the document, for example the exercise package.
With TeXstudio, the following magic comment can be used to automatically compile both versions at once (including repeated compilation for cross-references, bibliographies, indices etc.):
% !TeX program = latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=% -pretex="\newcommand{\version}{noanswer}" -usepretex % | latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=%_solution -pretex="\newcommand{\version}{}" -usepretex % | txs:///view-pdf "?am)_solution.pdf"
\documentclass{article}
% setting a default value in case it is compiled without the magic comment
\ifdefined\version
\else
\def\version{noanswer}
\fi
\usepackage[\version]{exercise}
\begin{document}
\begin{Exercise}[title={Title},label=ex1]
question text
\end{Exercise}
\begin{Answer}[ref={ex1}]
solution
\end{Answer}
\end{document}

Set the language of a listings environment in pandoc

I am struggling to convince pandoc to set the language for a listing automatically when converting from extended markdown (pandoc) to latex with the --listings argument. This is the file foo.txt:
A listing follows.
~~~{.prolog}
% fooing around
foo :-
format("bar~n").
~~~~
When I use pandoc -s foo.txt -o foo.html, the code is highlighted.
When I use pandoc -s foo.txt -o foo.latex, the code is highlighted, using the custom commands inserted by pandoc in the LaTeX preamble.
When I use pandoc -s foo.txt --listings foo.latex, the code is not highlighted, as the language option to the listings environment is not set. I can work around this:
~~~{.prolog language=Prolog}
but this defeats the purpose. Am I missing something or is this functionality not supported? If it omitted on purpose, what is the reason?

Run LaTeX command in Sublime 3

I'm working with LaTeX files in Sublime 3 (3059). Given a main .tex file and a .bib file holding the citations, I'd like to be able to issue the standard:
pdflatex main.tex && bibtex main.aux && pdflatex main.tex && pdflatex main.tex
command after hitting a given shortcut in Sublime.
I know there are tools that can do this (LatexTools, LaTeXing) but since what I need is (I believe) so simple, I'd prefer not to depend on extra packages.
How can I store this command and have Sublime run it following a given key combination?
Edit: Based on the answer given, this is the full command I ended up using:
{
"cmd": ["pdflatex $file_name && bibtex $file_base_name.aux && pdflatex $file_name && pdflatex $file_name"],
"shell": true
}
If you want to execute a command you could use Tools > Build System > New Build System to create a file with a content similar to this one:
{
"cmd": ["command"]
}
And then, you should select that as your project Build System. Finally, use ctrl+b to invoke build (invoke your command or script).

Markdown to PDF using Pandoc since Xetex Deprecation

On my MacBook (OSX Mountain Lion), I used to use this Pandoc command to convert Markdown to PDF:
$ markdown2pdf -N -o pandoc_output.pdf --xetex --toc --template=mytemplate.tex myfile.md
But markdown2pdf no longer works, and --xetex option in markdown2pdf -N -o ../../Desktop/pandoc_output.pdf --xetex --toc --template=mytemplate-headers-garamond_date.tex is deprecated.
If I do this:
$ pandoc -N -o Desktop/pandoc_output.pdf --xetex --toc --template=mytemplate.tex myfile.md
I get this:
pandoc: unrecognized option `--xetex'
But if I take out --xetex and do this:
$ pandoc -N -o Desktop/pandoc_output.pdf --toc --template=mytemplate.tex myfile.md
then I get this:
pandoc: Error producing PDF from TeX source.
! Package hyperref Error: Wrong driver option `xetex',
(hyperref) because XeTeX is not detected.
See the hyperref package documentation for explanation.
Type H <return> for immediate help.
...
l.3925 \ProcessKeyvalOptions{Hyp}
What's the solution?
Try --latex-engine=xelatex instead of --xetex
The prior answers to this question were helpful to me, as I had installed pandoc a couple years ago, but never Tex Live. Consequently I had no idea if I had installed it correctly, so putting in the entire path helped me to see that it was working, as follows:
pandoc --latex-engine=/usr/local/texlive/2012basic/bin/universal-darwin/xelatex
This is the default install location for the BasicTex setup which you download from the Pandoc install page.
I had also forgotten about using pandoc -D Latex >my-latex-template.tex to generate a template. After giving a .tex template instead of my .html one (which caused a 'you don't have BEGIN {' error) , I got .PDF: In other words, the default template worked.
Also, I had inaccurately entered -t pdf (not shown above) to set pdf as an output format, but this was not correct. The output format is Latex, which is then translated to PDF. It is not necessary to specify an output format with the dash -t option.
I hope this record of my minor stumbles saves someone some time.
See the pandoc User's Guide (or man page) for the --latex-engine option.

Resources