This guide will help you set up and use LaTeX with Visual Studio Code for document creation, particularly for documents with Thai language support.
MacTeX is the standard LaTeX distribution for macOS that includes all necessary LaTeX packages and compilers.
# Download and install MacTeX from:
# https://www.tug.org/mactex/
# Or install via Homebrew (recommended)
brew install --cask mactex-no-gui
Note: MacTeX is a large download (~4GB). The mactex-no-gui
version excludes GUI applications to save space.
Download and install VS Code from https://code.visualstudio.com/
- Open VS Code
- Go to Extensions (Cmd+Shift+X)
- Search for "LaTeX Workshop"
- Install the extension by James Yu
This project uses the following structure:
thesis-proposal/
├── main.tex # Main LaTeX document
├── main.pdf # Generated PDF output
├── font/ # Custom fonts directory
│ └── Sarabun/ # Thai font family
│ ├── Sarabun-Regular.ttf
│ ├── Sarabun-Medium.ttf
│ ├── Sarabun-Italic.ttf
│ └── ...
├── images/ # Images and figures
│ ├── platform_1.png
│ └── platform_2.png
└── README.md # This guide
This project includes a pre-configured VS Code task for building with XeLaTeX:
- Open the Command Palette (Cmd+Shift+P)
- Type "Tasks: Run Task"
- Select "Build LaTeX with XeLaTeX"
The LaTeX Workshop extension provides automatic building:
- Save your
.tex
file (Cmd+S) - The extension will automatically compile the document
- View the PDF in the integrated viewer
You can also build manually using terminal commands:
# Build with XeLaTeX (required for Thai fonts)
xelatex -interaction=nonstopmode main.tex
# For documents with bibliography
xelatex main.tex
bibtex main
xelatex main.tex
xelatex main.tex
This project uses XeLaTeX instead of standard LaTeX because:
- Unicode Support: Better handling of Thai characters
- Font Flexibility: Can use system fonts and custom fonts
- Advanced Typography: Better text rendering for non-Latin scripts
The document includes:
- Custom Sarabun font family for Thai text
- Proper font configuration for Thai typography
- Unicode support for Thai characters
The project includes optimized settings for:
- Automatic compilation with XeLaTeX
- Custom build tasks
- Thai language support
- Files are compiled automatically when saved
- Progress shown in the status bar
- Error messages displayed in the Problems panel
- Integrated PDF viewer
- Sync between source and PDF (SyncTeX)
- Side-by-side editing and preview
Cmd+S
: Save and compileCmd+Option+V
: View PDFCmd+Option+J
: Navigate to PDF locationCmd+Option+C
: Clean auxiliary files
- LaTeX command completion
- Environment snippets
- Symbol insertion
- Citation management
Problem: Thai characters appear as boxes or missing characters
Solution:
- Ensure XeLaTeX is used (not pdfLaTeX)
- Verify font files are in the correct location
- Check font path in the LaTeX document
Problem: Document fails to compile
Solution:
- Check the Problems panel in VS Code
- Review the LaTeX log file
- Ensure all required packages are installed
Problem: PDF doesn't reflect recent changes
Solution:
- Save the file (Cmd+S) to trigger compilation
- Check if there are compilation errors
- Try cleaning auxiliary files and rebuilding
LaTeX generates several auxiliary files during compilation. To clean them:
# Remove auxiliary files
rm *.aux *.log *.out *.synctex.gz *.toc *.lof *.lot *.bbl *.blg
Or use the LaTeX Workshop command:
- Command Palette (Cmd+Shift+P)
- "LaTeX Workshop: Clean up auxiliary files"
Consider installing these additional extensions:
- LaTeX Utilities - Additional LaTeX tools
- Code Spell Checker - Spell checking for documents
- Better Comments - Enhanced comment highlighting
- Bracket Pair Colorizer - Better bracket matching
- Keep images in a separate
images/
folder - Use meaningful file names
- Comment your code extensively
- Use Git for version control
- Commit frequently with meaningful messages
- Consider using
.gitignore
for auxiliary files
- Write content first, format later
- Use labels and references for cross-references
- Preview frequently to catch errors early
Create a .gitignore
file to exclude auxiliary files:
# LaTeX auxiliary files
*.aux
*.bbl
*.bcf
*.blg
*.fdb_latexmk
*.fls
*.log
*.out
*.run.xml
*.synctex.gz
*.toc
*.lof
*.lot
*.acn
*.acr
*.alg
*.glg
*.glo
*.gls
*.ist
*.lol
*.nav
*.snm
*.vrb
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Happy LaTeX writing! 🎓📝