LuaTeX-Ja: Specifying TTC Font Files - A How-To Guide
Hey guys! Ever struggled with getting LuaTeX-Ja to play nice with your TTC font files, especially on Fedora? You're not alone! This guide dives deep into how you can specify which TTC file LuaTeX-Ja should use, focusing on getting those Google Noto fonts working smoothly. Let's get started and make your Japanese typesetting a breeze!
Understanding the TTC Issue with LuaTeX-Ja
So, you're rocking Fedora 38 and trying to typeset some awesome Japanese text using Google Noto fonts. In LibreOffice, everything's peachy, but LuaTeX-Ja is throwing a tantrum. The problem often lies in how LuaTeX-Ja handles TrueType Collection (.ttc) files. A TTC file is basically a container holding multiple font faces. When LuaTeX-Ja encounters one, it needs to know exactly which font face within that collection you want to use. If it doesn't, things can get messy, leading to font substitution or outright errors. The default settings might not correctly identify the specific font within the TTC file, causing issues with rendering. Different applications handle TTC files differently. LibreOffice might have built-in mechanisms to correctly identify and use the fonts within a TTC file, while LuaTeX-Ja requires more explicit configuration. The key is to tell LuaTeX-Ja precisely which font face inside the TTC file to use, which involves specifying both the TTC file and the font index within it. This ensures that the correct glyphs are rendered, maintaining the intended appearance of your document. By understanding the intricacies of TTC file handling in LuaTeX-Ja, you can avoid common pitfalls and achieve consistent and accurate typesetting results, especially when working with complex scripts like Japanese.
Step-by-Step: Specifying the TTC File
Okay, let's get our hands dirty. Here's how to tell LuaTeX-Ja which TTC file to use, especially focusing on resolving issues with Noto Sans Mono. Follow these steps, and you'll be golden:
1. Find the Font Index
First, you need to figure out the index of the specific font you want within the TTC file. The font index refers to the order in which the font appears in the TTC file. Luckily, there's a neat little command-line tool called ttcindex that comes to the rescue. If you don't have it already, install it using your Fedora package manager:
sudo dnf install fonttools
Once installed, use ttcindex to list the fonts within your TTC file. For example, if your Noto Sans Mono TTC file is located at /usr/share/fonts/google-noto/NotoSansMono-Regular.ttc, run:
ttcindex /usr/share/fonts/google-noto/NotoSansMono-Regular.ttc
This will output something like:
0: NotoSansMono-Regular
The 0 in this output is your font index. Remember this number; we'll need it later.
2. Configure LuaTeX-Ja
Now, we need to tell LuaTeX-Ja to use the correct font from the TTC file. This is usually done in your LaTeX preamble. Use the ewfontfamily command, along with the Path and FontFace options. Here's an example:
\newfontfamily\notosansmono[
Path = /usr/share/fonts/google-noto/,
Face = {Regular}{}, % {<weight>}{<slant>}
Extension = .ttc,
FontFace = NotoSansMono-Regular
]{NotoSansMono-Regular.ttc[0]}
Let's break this down:
\newfontfamily\notosansmono: This defines a new font family callednotosansmono. You can name this whatever you like.Path = /usr/share/fonts/google-noto/: This specifies the directory where your TTC file lives.Face = {Regular}{}: This indicates the font face. In this case, we are using the regular font.Extension = .ttc: This specifies that the font file is a TTC file.Fontface = NotoSansMono-Regular: This is very important. Specify the font face name. Usually, it matches the file name.NotoSansMono-Regular.ttc[0]: This is the critical part. It tells LuaTeX-Ja to useNotoSansMono-Regular.ttc, and the[0]specifies that it should use the font at index 0 within that TTC file. Make sure the index matches the output from thettcindexcommand!
3. Use the Font in Your Document
With the font family defined, you can now use it in your document. For example, to use Noto Sans Mono for a specific piece of text, you'd do:
{\notosansmono This is some Japanese text in Noto Sans Mono.}
Or, to set it as the default font for your entire document, you could use:
\renewcommand{\rmdefault}{notosansmono}
\renewcommand{\sfdefault}{notosansmono}
\renewcommand{\ttdefault}{notosansmono}
4. Troubleshooting
Still having issues? Here are a few things to check:
- Case Sensitivity: Make sure the font names and file paths are exactly correct, including capitalization.
- Font Cache: Sometimes, LuaTeX-Ja can get confused by cached font information. Try clearing your font cache. The location of the font cache varies depending on your TeX distribution. A common location is
~/.texmf-var/luatexja-cacheor~/.texlive/texmf-var/luatexja-cache. Deleting the contents of this directory might help. - Missing Font Features: Ensure the font has the necessary features for Japanese typesetting. While Noto Sans Mono should be fine, it's worth verifying.
- LuaTeX-Ja Version: Make sure you're using a recent version of LuaTeX-Ja. Older versions might have bugs related to TTC file handling.
Alternative Approach: Using Fontconfig
Another way to handle this is through Fontconfig, which is a system for configuring and customizing font access. This is a bit more advanced, but it can be useful if you want a more system-wide solution.
1. Create a Fontconfig Configuration File
Create a new file in your Fontconfig configuration directory (usually ~/.config/fontconfig/conf.d/). Let's call it 99-notosansmono.conf:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="pattern">
<test qual="any" name="family">
<string>Noto Sans Mono</string>
</test>
<edit name="fullname" mode="assign">
<string>Noto Sans Mono Regular</string>
</edit>
<edit name="fontformat" mode="assign">
<string>TrueType</string>
</edit>
<edit name="index" mode="assign">
<int>0</int>
</edit>
</match>
</fontconfig>
2. Explanation
- This configuration file tells Fontconfig that whenever a program requests the font "Noto Sans Mono", it should:
- Use the font at index 0 within the TTC file.
- Treat it as a TrueType font.
3. Update Fontconfig Cache
After creating the file, update the Fontconfig cache by running:
fc-cache -f -v
4. Use in LuaTeX-Ja
Now, in your LuaTeX-Ja document, you can simply use the font family name:
\newfontfamily\notosansmono{Noto Sans Mono}
Fontconfig should now handle the TTC file selection automatically.
Wrapping Up
Dealing with TTC files in LuaTeX-Ja can be a bit tricky, but with the right approach, you can get your Google Noto fonts working perfectly. Remember to use ttcindex to find the font index, configure LuaTeX-Ja with the Path, Face, and font index, and clear your font cache if you run into problems. And if you're feeling adventurous, Fontconfig provides a more system-wide solution. Happy typesetting, folks! Let me know in the comments if you have any questions or run into any snags. I'm here to help!