Tx · LaTeX & TikZ

How to Run Commands in TeXnicCenter on Windows

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose the command type

    Use a build profile for LaTeX compilation; use a custom tool for a separate program or Windows command.

  2. 2. Check MiKTeX access

    Confirm Windows can find the relevant executable, or enter its full path in TeXnicCenter.

  3. 3. Configure the command

    Set the program, its arguments, and the working directory in the appropriate TeXnicCenter settings.

  4. 4. Run and inspect output

    Launch the profile or tool, then check its output and any generated files for errors.

TeXnicCenter can start MiKTeX’s LaTeX programs to compile a document, and it can also launch other Windows programs as custom tools. These are configured in different places: build profiles control the compile process, while custom tools are for separate commands such as a script, converter, or cleanup utility.

The menu names and available options can differ between TeXnicCenter versions. The examples below use the common Windows layout; if a menu or setting is missing, check the documentation for your installed version.

Compile a LaTeX document with MiKTeX

  1. Make sure MiKTeX is installed and that Windows can find the compiler. Open Command Prompt and enter where pdflatex. If Windows reports that it cannot find the program, use the compiler’s full path in TeXnicCenter or correct MiKTeX’s PATH configuration.
  2. In TeXnicCenter, open Build > Define Output Profiles (the wording may vary slightly by version).
  3. Select the profile you want to use, such as a PDF profile, and check that its LaTeX compiler is MiKTeX’s pdflatex.exe or another appropriate compiler. If the executable is not found automatically, browse to it or enter its full path.
  4. Check the compiler arguments and output settings. Keep the options supplied by the profile unless you know why you need to change them. Save the profile and build the document using the Build menu or its toolbar button.

A profile is more than a command name: it also tells TeXnicCenter how to pass the current document to the compiler and where to expect generated files. Replacing its arguments casually can make a working profile fail.

Run a separate program as a custom tool

For a command that is not part of the document’s normal LaTeX build, add a custom tool. In many TeXnicCenter versions, open Tools > Customize, then use the Tools tab to add an entry. Provide the program, its arguments, and—if the dialog offers it—the working directory. Save the configuration and run the new entry from the Tools menu.

For example, to launch a Python script directly, the command can be the path to python.exe, and the arguments can be the script’s path. If the script uses files in the document’s folder, set that folder as the working directory where possible. This avoids relying on whichever directory TeXnicCenter happened to start in.

Windows shell commands are different from executable programs. Commands such as dir, copy, and echo are built into the command interpreter, so TeXnicCenter cannot generally launch them as standalone programs. Set the command to C:\Windows\System32\cmd.exe and the arguments to /c dir to run dir and close the command interpreter afterward. Use /k instead of /c if you want the command window to stay open. For a command containing paths or arguments with spaces, quote carefully; Windows command-line quoting can be sensitive to the exact command.

A batch-file example

A batch file is useful when you want to run several commands in order. Create C:\Scripts\check-project.bat with contents such as:

@echo off
cd /d C:\Work\MyProject
python check.py

Then configure a TeXnicCenter custom tool to run C:\Windows\System32\cmd.exe with arguments like /c C:\Scripts\check-project.bat. The cd /d line changes both the working directory and drive, so check.py is run from the project folder. If a path contains spaces, quote it and test the command in Command Prompt first.

If the custom-tool dialog provides a field for the initial directory, you can set that instead of changing directories in the batch file. For commands that need the current document’s filename, use TeXnicCenter’s variable-insertion control if your version provides one; do not assume that a placeholder copied from another version will expand correctly.

Common mistakes

  • Entering a shell command as the program: dir is not an executable file. Run it through cmd.exe /c, or put it in a batch file.
  • Using a path TeXnicCenter cannot find: Check the executable in Command Prompt with where, or specify its full path in the tool or output profile.
  • Ignoring the working directory: A program may start successfully but fail to find input files because it is running from a different folder. Set the initial directory or change to the project folder in a batch file.
  • Confusing compilation with a custom command: A custom tool does not automatically become part of every document build. Use an output profile and its build sequence when the command must run as part of compiling a document.
  • Overwriting compiler arguments: Removing filename or output options from a LaTeX profile can prevent TeXnicCenter from building the current file or locating the PDF.

If a command works in Command Prompt but not in TeXnicCenter, compare the executable path, arguments, quoting, environment variables, and working directory. Testing the same command in a small batch file can help isolate which setting is causing the problem.

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.