To get the current $USER in LaTeX - latex

My friend has the following in his computer in a LaTeX document
\includegraphics[width=13.0cm]{/Users/max/Dropbox/2_user_cases.png}
I would like to have a variable for the username such that we can collaborate faster.
Pseudo-code about what I wont
\includegraphics[width=13.0cm]{/Users/`echo $USER`/Dropbox/2_user_cases.png}
How can you have such an command inside LaTeX?

I'm not sure you can access envvars from LaTeX. As Rutger Nijlunsing has said, you can try "~/" since it is an alias to "/Users/<username>".
If there are other envvars that you need to access, my suggestion is using Makefile to 'compile' the .tex (or a shell script) calling sed to replace such word.
sed -i "s/max/$USER/" file.tex
latex file.tex
bibtex ...
latex ...

in the graphicx package, you can define a folder for latex to look for all your images in, like this:
\graphicspath{{images/}}
In this particular configuration, latex looks for a folder in the same directory as your file called "images."
I don't see why you'd want to use a full path just to get image in...
Make a folder, put your .tex source file in there, create a folder for your images.
Stick you work in some sort of revision control system (git, SVN, etc etc.)
Commit often, and you're on your way.

use ~ for your homedirectory (which is probably /Users/$USER):
\includegraphics[width=13.0cm]{~/Dropbox/2_user_cases.png}

Related

Creating pdf from subdir using latexmk -pdf

-Main Directory
- sub direcory
-xx.tex
- sub directory
-yy.tex
I am trying to create pdf file for all latex files, but it only works if I am in sub directory folder
example C:Users/Desktop/MainDirectory>sub directory latexmk -pdf I will get xx.pdf file
However if I did C:Users/Desktop/MainDirectory> latexmk -pdf
I will get error, saying No file name specified, and I couldn't find any
latexmk -pdf will look for a .tex file in your current directory. If it doesn't find any in the current directory, it doesn't recursively search for them anywhere else. After all, how does it know whether it should compile xx.tex or yy.tex, or how deep it should go?
You can provide a filename to it, though, telling it what file to compile, as latexmk -pdf subdir1/xx.tex, and it will output the files in the current working directory.
Note: this is probably not the best practice, you might as well go into subdir1 and run the same command (latexmk -pdf xx.tex) with the output-directory=.. command. I don't know why you would want all your tex compiles in the same folder, though, and separate the source codes.
On another note, while I see you're using Windows, you could recursively run all your texfiles in subdirs with the find command in Linux, as this: find . -name *.tex -exec latexmk -pdf {} \;. This might lead to issues if some texfiles have the same name. Omit the trailing -exec... to run a dry-run to see which files you want.

What do I need to do to "register" 'latexpdf' for Sphinx?

When I run Sphinx using 'latexpdf' I get an error, even though I have a complete working TeX installation on my machine:
Sphinx error: Builder name latexpdf not registered
What do I need to do to "register" latexpdf?
latexpdf is not a Sphinx builder; it is the name of a target in the Makefile created by sphinx-quickstart. This target uses the latex builder.
Executing sphinx-build -b latexpdf . _build produces the error in the question (as expected).
If you run make latexpdf, it works.
PyCharm was mentioned in a comment and the problem seems to stem from that program. The following is run when latexpdf is configured as a "Command" (Sphinx task):
sphinx_runner.py -b latexpdf <indir> <outdir>
The sphinx_runner.py script is very similar to sphinx_build (a wrapper for sphinx.cmdline.main()). Since the -b option is supposed provide the name of an actual builder, there is an error.
Use -M instead of -b. This invokes sphinx-build similarly to make latexpdf, e.g.:
sphinx-build -M latexpdf . _build
See #mzjn's answer for details.
Now have Pycharm 2016.3 generating a pdf form me based on information here: https://www.quora.com/How-to-create-a-PDF-out-of-Sphinx-documentation-tool
Install rst2pdf:
pip install rst2pdf
Edit a new Python Docs sphinx configuration and choose pdf as the command. Set input directory and directory to hold .pdf as output.
Edit the conf.py file and add the two lines that mention pdf:
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'rst2pdf.pdfbuilder'
]
pdf_documents = [('index', u'documentation', My Docs', u'Me'), ]
Now run the configuration and you should get a file called documentation.pdf in the output directory.
If you are interested in a pure Python solution, the following works for me:
import sphinx.cmd.make_mode as sphinx_build
OUT_DIR = "docs" # here you have your conf.py etc
build_output = os.path.join(OUT_DIR, "_build")
# build HTML (same as `make html`)
build_html_args = ["html", OUT_DIR, build_output]
sphinx_build.run_make_mode(args=build_html_args)
# build PDF latex (same as `make latexpdf`)
build_pdf_args = ["latexpdf", OUT_DIR, build_output]
sphinx_build.run_make_mode(args=build_pdf_args)
In fact, I've made a complete Python3 script that given a few convenient arguments generates the whole package documentation as HTML and PDF from scratch, with the RTD theme. It can be pretty handy if you want it to run it on different OS or Python interpreters (in my case i wanted to run it within Blender), or adapt it to your needs. It still has some dirty spots, due to some variables being hardcoded into conf.py. Let me know if you see any issues with it!
This is how it looks like:
HTML
PDF
Cheers,
Andres

How to see vimrc files used during startup

I've moved my vimrc file out of the home directory to pathogenize the setup, but it looks like my vim is still picking up a redundant vimrc file that I made somewhere. Is there some variable in vim that I can echo that'll show what files were used during startup?
:scriptnames lists all sourced script names, in the order they were first sourced.
Look for the $MYVIMRC variable:
:echo $MYVIMRC
After starting vim, you can type
:set runtimepath
See the docs here: http://vimdoc.sourceforge.net/htmldoc/options.html#'runtimepath'
I don't think #skinp's answer is necessarily sufficient. the runtimepath variable is the very definition of all places vim looks
Additionaly, you can launch Vim with
$ vim --startuptime filename
which should write a list of loaded scripts (including vimrc) and their respective processing time to file filename.

Opening a db/migrate/* file more effectively? Wildcard to complete the beginning of the name of the file?

Working from a bash shell and utilizing vim, I generally have a pretty effective workflow. However, when I attempt to access files in the db/migrate directory of a rails project, it becomes very tedious to access the files as the each contain a long integer at the being of their file names. I've tried vim db/migrate/*name_of_migration.rb but to no avail.
Is there a way to access files via wildcard of in this manor?
If you're using vim-7.3, then you can do this from inside vim:
:set path=/path/to/your/project/root/**
:find migrate/*cr<tab>
and vim will show you the possible candidates for completion.
If you're typing the name of the migration correctly, I assure you that the * will match the leading digits.
For example, from the root of your project,
$ vim db/migrate/*create_users.rb
will open 20111123142812_create_users.rb.
Otherwise, my preferred method is to use
$ vim db/migrate
to "open" the directory in vim, and use the in-vim navigator to select the migration you're interested in from the list of files.

vimrc - current working directory

I would like to be able to access the current working directory in my vimrc.
For example, I can access the current file by using %.
Specifically,
I have the following line in my vimrc:
map ,l :!latex %
When it runs everything works fine, except the resulting dvi and other files are stored in my home directory instead of my current working directory.
Any suggestions?
See :help autochdir. Vim can automatically change the current working directory to the directory where the file you are editing lives.
Otherwise, if you want to do this manually, see :help cd and :help lcd.
see :he filename-modifiers
:!latex % -output-directory %:h
Most likely, you're running vim from your home directory, so it is the current for him. The latex command, being invoked from vim, also therefore has the home directory as current.
You probably know this, and want just to extract path from the filename and supply it as an argument to -o option of the latex command. Just use the shell capabilities:
:!latex % -output-directory `dirname "%"`
I am not sure that it's -output-directory option, but you get what you asked for--a directory name of the file you're editing.

Resources