tools

LaTeX with SublimeText and Skim

SublimeText with LaTeX Tools plugin

Recently I started writing my Master Thesis. I decided I will do it in LaTeX.

I work most of the time on MacBook. The most popular LaTeX distribution for Mac is MacTeX (for Windows: MiKTeX or TeXlive). Once I had this installed I needed editor. First I was using TeXworks, but it is not very decent environment. Nice thing about it is the built-in PDF viewer. Every time I rebuild the document it refresh generated pdf. However, it’s hard to manage documents with more than one .tex file. My Master Thesis consists multiple files and I end up editing files in SublimeText and building pdf with TeXworks. Not cool!

Today, one friend of mine showed me application, which detects .pdf updates automatically: Skim. I have also found LaTeXTools plugin for SublimeText. It allows to build .tex document with CMD+B (Mac) or CTRL+B (Windows/Linux). Moreover, Skim can be integrated with SublimeText in such a way that it checks for updates every time, you perform build in SublimeText.

LaTeX + SublimeText + Skim setup

  1. Install LaTeX distribution (for Mac OS X: MacTeX, for Windows: MiKTeX or TeXlive).
  2. Install SublimeText
    • Optionally: Install SublimeText Package Control (if you didn’t do that already) – it will be easier to install LaTeXTools package.
  3. Install LaTeXTools plugin. With SublimeText Package Control installed: click CMD+SHIFT+P (on Mac) or CTRL+SHIFT+P (Win/Linux). More details can be found here.
    • Mac users: You may need to install ‘latexmk’: sudo tlmgr install latexmk (more info can be found in LaTeXTools README).
  4. Install Skim (for Windows users: check Sumatra PDF).
  5. In Skim: go to Preferences->Sync and set ‘preset’ to SublimeText.

Skim preferences

After that you just need to build LaTeX document in SublimeText with CMD+B (Mac) or CTRL+B (Win/Linux). Open the generated .pdf in Skim, then every time you rebuild it in SublimeText – it will be refreshed automatically.

If you have multiple documents add %!TEX root = <master file name> at the beginning of every file.

It is much more convenient than using SublimeText and TeXworks for rebuilding pdf. Additionally, TeXworks’ PDF viewer is not very decent.

For LaTeX editing, I have found also TeXstudio. It looks good, but I didn’t test it so far.


Update to Windows 8.1 from Windows 8

Before you decide to upgrade your Windows 8 to 8.1, you should be aware of some issues/changes.

To begin with, it is not very obvious and easy to find a way, to avoid using Microsoft Account. Fortunately, Scott Hanselman described it in his blog, in his post How to sign into Windows 8 or 8.1 without a Microsoft account – make a local user.

Another issue is SkyDrive. If you are not using it, then you do not need to worry. But if you do (like me) then be aware that now it is integrated with Windows 8.1. You are not able to use SkyDrive app like in Windows 8. What is more: you need to sign in with Microsoft Account on Windows 8.1, to be able to use SkyDrive. In the recent version of SkyDrive, Microsoft introduced “smart files”. It distinguish two types of files: online-only (not stored on your hard drive and available when you are connected to the Internet) and offline (old-style files, can be used when you are offline and will be synced once you get online). Default status of new created file is online-only. You need to change it if you want to use files in the old-way (offline). There are two ways to do that. First: go to SkyDrive app and mark file/directory you want to make offline (by right click) and click “Make offline” in app bar:

SkyDrive - make offline

Second way is go to SkyDrive settings and set “Access all files offline” to “On”:

SkyDrive - access all files offline

You can find more details about “smart files” here.

All above issues are fixable. However there are a few things, which cannot be solved (so far). I have ThinkPad X220 (i5@2.3GHz, 8GB RAM, 160GB SSD) and I did a system upgrade from Win8 to Win8.1. Since then, the performance is a little bit worse. Additionally, I have two monitors connected through VGA and DisplayPort. The second monitor is all gray right after system boot. I need to click WIN+D to get the desktop. I do not have this issue on my PC where I installed Win 8.1 from scratch.

I use PowerShell as my default command line. There is a weird issue with Lucidia Console font on Windows 8.1. You cannot set it as default font. It is not a huge concern, because the Consolas works fine, but I cannot use Lucidia Console (which I like better). More about this issue here.

Now, let’s look at the bright side of life. My favorite Windows 8.1 feature is “search everywhere”. You do not need to think whether you want to search programs (WIN+Q), settings (WIN+W) or files (WIN+F). However, Everything Search Engine is still the best for searching files.

I like the Windows button too. After right-click, you have the same menu which you get with WIN+X. Furthermore, there are options shutdown/restart/sleep there. It is easier and faster accessible than “Mouse to right-bottom corner of screen”->Settings->Power->Shut down.

Another nice feature is the adjustable size of tiles:

Windows8.1 - adjustable tiles

To learn about other new features I recommend Scott Hanselman’s videos about new features in Windows 8.1. He is showing how to be productive on Windows 8.1 and how to take advantage of key shortcuts.

By the way: Happy New Year 2014!

Happy New Year 2014


Symbolic Links in Windows

Since Windows Vista we have possibility to create symbolic links on Windows. Yay!

To do that, we have command mklink in Command Prompt:

C:\Users\jj\Desktop>mklink link_to_some_file.txt c:\Dropbox\some_file.txt
symbolic link created for link_to_some_file.txt <<===>> c:\Dropbox\some_file.txt

Symbolic link is not a shortcut. However, its icon desktop looks the same:

link and shortcut icons in Windows

You can find out whether it is a link or shortcut by looking on the properties (left – link, right – shortcut):

link vs shortcut in Windows

You can also check it from the command prompt:
C:\Users\jj\Desktop>dir
Volume in drive C has no label.
Volume Serial Number is A425-1CEF

Directory of C:\Users\jj\Desktop

11/15/2013 10:36 AM <DIR> .
11/15/2013 10:36 AM <DIR> ..
11/15/2013 10:35 AM <SYMLINK> link_to_some_file.txt
11/15/2013 10:36 AM 921 some_file - Shortcut.lnk
2 File(s) 921 bytes
2 Dir(s) 15,738,155,008 bytes free

OT: Don’t you think dir command is to verbose? Who needs e.g. Volume Serial Number each time during listing directory?

In PowerShell, you need to use following command: cmd /c mklink (precede mklink with cmd /c).

I use it for my PowerShell config file. Original one is in Dropbox and symlink just point to it from MyDocuments directory (where it has to be, to be applied by PowerShell).


Windows PowerShell profile

Windows PowerShell is very powerful tool. It contains many useful commands. One of my favorite features is possibility to use some well-known bash commands such as: ls or pwd, which are missing in Windows Command Prompt. The cool thing is the fact, that PowerShell contains combination of Windows Command Prompt and Bash shell commands. E.g. for copying you can use copy (Windows) and cp (Bash).

You can also have personal configuration file (like .bashrc in Unix) to set some persistent settings. To find out, where it is located use command:

PS C:\> echo $PROFILE
C:\Users\jj09\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

I needed to create directory ‘WindowsPowerShell’ and profile file before adding some custom settings. Additionally, I needed to enable scripts on my system (it is disabled by default).

PS C:\> Set-ExecutionPolicy RemoteSigned

More info about Execution Policies can be found here.

My Microsoft.PowerShell_profile.ps1 file:

set-alias subl "C:\Program Files\Sublime Text 2\sublime_text.exe"
set-alias grep select-string
set-alias ssh New-PSSecureRemoteSession
set-alias sh New-PSRemoteSession
set-alias l ls

There is also ‘Power’ version of PowerShell called ISE (Integrated Scripting Environment). Be aware, that it has different profile file (for me it is: C:\Users\jj09\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1). You can check it with the same command like for standard PowerShell (echo $PROFILE). Here is a list of top 10 killer features, which are in ISE, but not in standard PS (Intellisense is my favorite).

PowerShell-autocomplete

Disadvantage of PowerShell is its loading time. Windows Command prompt loads instantaneously, but PS need ~1 second. It is even worse in case of ISE, which needs ~3 seconds (on my Thinkpad X220: i5/8GB/SSD).

You can add custom configuration to Windows Command Prompt too. To do that you need to run command prompt with some arguments.


scriptcs – C# in console

It was always bothering me, when I wanted to run one simple command, and I needed to create new C# console project in Visual Studio to do that. With scriptcs I can finally do that in console. Project scriptcs allows you to run single commands and also C# script files.

Installation

The easiest way to install scriptcs is Chocolatey (‘apt-get’ for windows). If you didn’t hear about it, you should definitely try it out. To install Chocolatey run the following command in console:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

Once you have Chocolatey installed, you can install scriptcs:

cinst scriptcs

Chocolatey will install scriptcs to %APPDATA%\scriptcs\. You need to update your PATH accordingly, to easily run it from command line.

Getting started

Once scriptcs is installed and added to your PATH, you can run it with scriptcs command:

C:\> scriptcs
scriptcs (ctrl-c or blank to exit)

> var message = "Hello, world!";
> Console.WriteLine(message);
Hello, world!
>

C:\>

You can also create a script hello.csx:

var message = "Hello, world!";
Console.WriteLine(message);

And run it from command line:

C:\>scriptcs hello.csx
Hello, world!

You can find more about scriptcs on scriptcs.net.

EDIT: You don’t even need Console.WriteLine to print variables (thanks Filip W.):

C:\>scriptcs
scriptcs (ctrl-c or blank to exit)

> var message = "Hello, scriptcs!";
> message
Hello, scriptcs!
> int four = 2 + 2;
> four
4
>