GeneralRefer to file in package directory

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Refer to file in package directory

Post by hugovdberg »

I want to create a custom package to handle all my default font settings, and I have a number of otf files I want to include in my output using fontspec. What I don't want to do is copy these files to every project folder I create, and I want a solution that works both under Windows and Ubuntu Linux. To have identical files in both environments I use Dropbox and have a subfolder included as tex directory, so my packages are found just fine. Unfortunately I am not allowed to include the necessary OTF due to licensing, but a (random google result) OTF font can be downloaded from http://www.mediafont.com/font-10360-yan ... esatz.html

Does anyone know how to get the currentdirectory of the package file, I tried currfile and \currfiledir but that doesn't seem to work.

main.tex:

Code: Select all

\documentclass{scrartcl}
\usepackage{myfonts}

\usepackage{blindtext}
\begin{document}
\blindtext
\end{document}
with myfonts.sty in a different directory than main.tex, and otf files in same directory as myfonts.sty:

Code: Select all

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{myfonts}[2014/02/05 My custom fonts]

\RequirePackage[T1]{fontenc}
\RequirePackage{fontspec}
\setmainfont[Numbers={OldStyle,Proportional}]{calluna-regular.otf}

\endinput
Last edited by cgnieder on Thu Feb 06, 2014 11:23 am, edited 1 time in total.
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Refer to file in package directory

Post by cgnieder »

Your file loads both fontspec and fontenc which is wrong. You need either the first (with pdfLaTeX) or the second with XeLaTeX or LuaLaTeX.

fontspec is able to use system fonts so the easiest seams to me to install the fonts on your system and then just to use it in the document with fontspec.

Regards
site moderator & package author
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Refer to file in package directory

Post by hugovdberg »

Ok, I'll remove the fontenc package, but is there no way for LaTeX to know from what directory a package was loaded? I find myself working on different systems and/or reinstalling the OS quite regularly, so I am really happy with Dropbox as my custom package repo. I have tried to google for a solution but as soon as you google for anything with latex and directory you only get results for installation of packages :cry:
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Refer to file in package directory

Post by cgnieder »

hugovdberg wrote:but is there no way for LaTeX to know from what directory a package was loaded?
It depends a bit on the distribution. I have little to no knowledge about MiKTeX. In TeX Live packages usually are placed in the local texmf tree and then the database is updated with mktexlsr. Here you'll find more information: http://tex.stackexchange.com/q/1137/5049

Regards
site moderator & package author
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Refer to file in package directory

Post by hugovdberg »

While on the subject of fonts and fontenc vs fontspec, is the distinction pure based on whether you use pdflatex or lualatex (fontenc with the first and fontspec with the latter), or just that you don't need fontenc when you also use fontspec (and thus lualatex) and is fontenc+lualatex just fine as well?

I'm still figuring out how I want to setup my fonts, but I think I'm going to give in since this problem seems to be a bit harder than I thought it would be. I guess it takes more effort to set it up once this way than to do a manual install of the fonts on every system when necessary. I can still use Dropbox to have the otf-files available with the package :)
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Refer to file in package directory

Post by Johannes_B »

You can use fontspec with either LuaLaTeX or XeLaTeX, it loads fontenc implicitly, but with different options, depending on the engine you are using.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply