0

I am trying to setup a pipeline in DevOps using a Linux distribution to build LaTeX documents using texlive. I got the texlive installed and has also confirmed that it is working. However, my latex documents use our style document to have the same layout in all documents, and this is where my problem starts. No matter what I do, texlive just cannot find my .sty file.

I have tried to register my sty file within the TEXMFHOME folder, explained under this entry: Where do I place my own .sty or .cls files, to make them available to all my .tex files?, but that failed. Here is the script I attempted:

#!/bin/sh
#Creating comments

#setting TEXMFHOME
texmfhome=$(kpsewhich -var-value=TEXMFHOME)
echo texmfhome: $texmfhome

echo Creating TEXMFHOME/dxpc:
mkdir -p -v $texmfhome/dxcpc   

echo Coping sty document
cp -v pathtostydocument/mystyle.sty $texmfhome/dxcpc/mystyle.sty

echo texhash $texmfhome/dxcpc   
texhash --verbose $texmfhome/dxcpc   

echo Verifying installation:
cd $texmfhome
kpsewhich mystyle.sty

The weird thing about this approach is that TEXMFHOME points to /home/vsts/texmf, but the texmf folder does not exist, so I create it first and place my style folder in a sub folder called dxcpc. According to various pages online, this should mean that I could skip the texhash call, allthough I do it anyway.

Then I found a SO entry that stated that I could just try and import the style document using paths: https://stackoverflow.com/questions/5993965/include-sty-file-from-a-super-subdirectory-of-main-tex-file. My latex file tree is this:

[Latex]
    - [Extensions]
        - [Ext1]
            - mainpage.tex
    - mystyle.sty

So I attempted to change my use package call in latex from this:

\usepackage{myStyle} 

to

\usepackage{../../myStyle} 

But texlive fails the same way, albait the message !LaTeX Error: File `../../mystyle.sty' not found.

I then also tried to move the style document to the same folder as the tex document i am building. But this fails the same way. The error I am getting in all 3 scenarios is the following:

/bin/bash --noprofile --norc /home/vsts/work/_temp/1a5a7e0d-09c3-4a75-b462-e2144e715abd.sh
Build Clients Tools readme.txt Starting pdflatex Build Clients Tools readme.txt
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode

(/pathtolatex/Extensions/Ext1/mainpage.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 3 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/report.cls
Document Class: report 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))

! LaTeX Error: File `mystyle.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name: 
! Emergency stop.
<read *> 
Transcript written on "mainpage.log".
Build Clients mainpage.log EGPaymentSolution Tools readme.txt Done pdflatex. Build Clients mainpage.log Tools readme.txt

Finishing: Build mainpage

When I try to build the document using scenario 2 and 3 in windows with MiKTeX, there is no problem and the system builds as expected. And if I removed the style document and build in my DevOps system it runs without issues. It just won't accepts style document in any of the cases I have tried and I haven't yet figured out why or if there is another way to make it work.

I was looking around online and got the idea that if I instead of including the style document as a package, I could just include it. So I changed the import to

\input{../../myStyle.sty}

My miktex distribution on windows compiles it as expected, but texlive still cannot locate the file:

LaTeX Error: File `../../myStyle.sty' not found.

I am beginning to wonder if I might have a deeper issue with ubuntu and the way it executes the texlive build command. Right now it seems that it will get the target file fine, but then it starts buildingfrom another base location than of my tex document location and then it can't find the resources it needs.

I have been looking into the documentation for kpathsea. I've read several pages and what Tex does, when it need to find a file is that it delegates that task to kpathsea. It then tries to look for the file. I am certain that I need to configure this the right way with some form of path, and i am still reading through the internet to figure out exactly where i need to do this. The configuration file is abit complex, but I have found some pages that I am looking into at the moment:

https://www.overleaf.com/learn/latex/Articles/An_introduction_to_Kpathsea_and_how_TeX_engines_search_for_files

https://www.tug.org/texinfohtml/kpathsea.html#Path-searching

http://kirste.userpage.fu-berlin.de/chemnet/use/info/kpathsea/kpathsea_2.html

evilfish
  • 101
  • TeX only finds your file in TEXMFHOME if TEXMFHOME follows the TeX directory structure. This is alluded to in the answer to the first question you cite, which says "Following the TeX directory structure, you should place your file in a subdirectory like ~/texmf/tex/latex/commonstuff/". See also https://tex.stackexchange.com/q/224483/35864 and in particular https://tex.stackexchange.com/q/252595/35864. In your case mystyle.sty should probably live in $texmfhome/tex/latex/dxcpc/mystyle.sty. Do not run texhash on your local TEXMFHOME. – moewe Feb 21 '20 at 06:38
  • 1
    I can't tell you exactly why your second and third attempt fail: If the .tex and .sty are in the same folder things should usually work. The only guess I have is that the working directory is not as expected. It is my understanding that when you run LaTeX it resolves all file references according to the current working directory. So when both the .tex and .sty are in /pathtolatex/Extensions/Ext1/ and you do cd /pathtolatex/Extensions/Ext1/ pdflatex mystyle.sty, then things should work. ... – moewe Feb 21 '20 at 06:43
  • ... But if you do say cd /pathtolatex pdflatex ./Extensions/Ext1/mystyle.sty, then TeX will try to resolve all file names relative to /pathtolatex and will not find anything. Always set the working directory to the directory where your main .tex file lives, that spares you a lot of troubles. – moewe Feb 21 '20 at 06:45
  • I tried to moved the executing directory and it seems to work really well with \usepackage{../../myStyle}. I locates the sty file in parent directory, which is excatly what i wanted. I do now have some other package i dont have downloaded yet. Currently i have ! LaTeX Error: File `sectsty.sty' not found, so more work for me. But now it runs in the right direction. Thank you so much! – evilfish Feb 22 '20 at 22:05
  • 1
    You should be able to install sectsty and other packages that are included in TeX live easily via tlmgr. (If you haven't installed a full TeX live already, that is.) – moewe Feb 23 '20 at 07:34
  • I had some issues but I got is all working. It took quite a long time downloading the packages, but the --no-persistent-downloads options speed it up. So now my build installs texlive, downloads necessary packages using tlmgr and builds as expected. Now i just need to do something with the documents, but that is not important for this issue. Thank you so much for your help. – evilfish Feb 24 '20 at 21:30

0 Answers0