I am trying to figure out if I can switch from Mac back to Linux after a gap of 10+ years. I installed an Ubuntu derivative on the machine, and installed TeXLive 2019 (vanilla) using the equivs business to create a dummy package called texlive-local, so that I can trick the OS into thinking that TeX is installed. This is necessary because Ubuntu LTS tex packages are outdated.
My paths are fine. I can execute pdflatex, etc. perfectly fine, and documents containing standard latex classes (or rather anything under /usr/local/texlive/2019 ...) work fine.
The problem starts when I try to compile anything that needs my custom authored classes (I have several), which I installed under /home/user/texmf (see details below).
Actually, after I initially had problems, I copied (cp -R as user, not root, not sudo) the entire texmf-local tree from /usr/local/texlive to /home/user/texlive, and placed symbolic links to folders containing my custom class files under /home/user/texmf/tex/latex/local/. While copying the empty tree from /usr/local/texlive is not required, doing so ensures that I have the right TDS tree under ~/texmf. It is good practice to do so. So, I have the following symlinks (ln -s):
customclass ---> ../../../../../Somepath/customclass
classone ---> ../../../../../Somepath/classone
classtwo ---> ../../../../../Somepath/classtwo
under /home/user/texmf/tex/latex/local where the .cls and .sty files are located under the symlinked folders above. I am writing this explicitly here so that no one has any misunderstanding about the nature of my texmf tree - the symlinks are to folders containing the class files, and not to the class files themselves.
I have tried setting TEXMFHOME explicitly at the end of my .bashrc, and also tried to manually export the variable, and added it to /usr/local/texlive/2019/texmf.cnf.
I have been a LaTeX user for about 22 years, and I do NOT recall using LaTeX being this hard under Linux.
On Mac, this was simple - just placing symlinks under ~/Library/texmf took care of everything. IIRC that was also the case (~/texmf) in the old days when I used LaTeX on Linux. Apparently, not anymore.
I have searched for several answers on stackexchange, and elsewhere, tried out what I found there, but it does not work. Any file using custom classes, still fails, with kpsewhich failing to find the .cls files. I have run kpsewhich on command line - my custom classes yield blank input, while article.cls produces the path to article.cls.
Edit: Yes, I have run texhash ~/texmf, and sudo texhash multiple times.
What am I missing? Before someone suggests the obvious - explicitly copy the files over to texmf, I do not want to do that. My folders containing class files are sync'ed across several machines using a combination of rsync, and cron jobs, and I don't want to maintain two copies of the same file. A symbolic link is the right tool for the job.
Edit: I backup the folders containing my class files, not ~/Library/texmf (on Mac) and not ~/texmf (on Linux). I just symlink to the backed up folder on each OS. There are multiple machines that use these class files (I run a lab, and my grad students need to be all on the same page).
Is kpsewhich on the Linux version of TeXLive broken in the sense that it cannot handle symlinks?
Given that the various answers I have found on stack exchange have slightly different situations from mine (the equivs + TeXLive install mainly), this question is not a duplicate.
Edit: I figured it out, see my answer below. The problem is that kpsewhich is lazy, and does not want to look at symlinks unless a real directory is also located at that level.