How to suitably configure the TEXINPUTS variable in latexmkrc for detecting the sty and cls files present in a custom folder in the project directory?

Latexmk actually has a subroutine for adding items to search paths. You can write

ensure_path( 'TEXINPUTS', './custom_cls_sty_files//' );

This takes care of using the correct operating-system-dependent separator between items in the variable. It also gracefully handles the case where the search-path variable doesn't already exist.

This subroutine is not yet documented, but it will be in the next release.

Documentation of ensure_path

ensure_path( var, values ...)

The first parameter is the name of one of the system's environment variables for search paths. The remaining parameters are values that should be in the variable. For each of the value parameters, if it isn't already in the variable, then it is prepended to the variable; in that case the environment variable is created if it doesn't already exist. For separating values, the character appropriate the the operating system is used -- see the configuration variable $search_path_separator.

Example:

ensure_path( 'TEXINPUTS', './custom_cls_sty_files//' );

(In this example, the trailing // is documented by TeX systems to mean that latex, pdflatex, etc search for files in the specified directory and in all subdirectories.)

Technically ensure_path works by setting Perl's variable $ENV{var}, where var is the name of the target variable. The changed value is then passed as an environment variable to any invoked programs.


Newer versions of Tex Live address the need for user or project specific sets of files to override the defaults. This should only apply to give priority to the files that are there others that are on texmf paths will be used as normal. Although untested I would NOT split a TDS package between the two locations, so you may need to duplicate in some cases package related support files so as to be found relative to each other.

This was introduced in Tex Live 2017 and is invoked by calling (irrespective of platform)

 tlmgr conf auxtrees [add | remove | show] <path to desired files>

For windows use it may be something like (avoiding spaces and accents etc.)

tlmgr conf auxtrees add C:\Users\myname\PersonalTexmf
tlmgr conf auxtrees show C:\Users\myname\PersonalTexmf

Linux or OS/X users may need to use sudo:

sudo tlmgr conf auxtrees add "./personal_texmf"

You may need to experiment with using TDS compliant folders but the related structure should be similar to within texmf-local.
see also https://www.tug.org/texlive/doc/texlive-en/texlive-en.html#x1-110002.3

IT is important that the aux tree is NOT within an existing texmf structure (to avoid potential conflicts of priority) however the auxiliary may be a folder alongside texmf-local

IF texmf-local files interfere in precedence then it may become necessary to temporarily block a default texmf-local folder first via a shell script or manually commenting out via alternative copies of your current texmf.cnf

Here is a hypothetical example session from the 2017 blog

$ tlmgr conf auxtrees show
tlmgr: no auxiliary texmf trees defined.
$ tlmgr conf auxtrees add /projects/book-abc
$ tlmgr conf auxtrees
List of auxiliary texmf trees:
  /projects/book-abc
$ tlmgr conf auxtrees remove /projects/book-abc
$ tlmgr conf auxtrees show
tlmgr: no auxiliary texmf trees defined.

That was very untypical, and we may need to address the filename database /font maps for the user prior to calling Tex Live in anger.

Note at the same time there were changes to

"The TEXMFLOCAL tree is now searched before TEXMFSYSCONFIG and TEXMFSYSVAR (by default);"

The defaults should be

"TEXMFLOCAL (by default, /usr/local/texlive/texmf-local or %SystemDrive%\texlive\texmf-local on Windows) is intended for system-wide local fonts and macros; and TEXMFHOME (by default, $HOME/texmf or %USERPROFILE%\texmf), is for personal fonts and macros. These directories are intended to stick around from release to release, and have their content seen automatically by a new TEX Live release. Therefore, it is best to refrain from changing the definition of TEXMFLOCAL to be too far away from the main TEX Live directory, or you will need to manually change future releases."

It may be useful to see the results with Kpathsea & Kpsewhich
https://www.tug.org/texlive/doc/texlive-en/texlive-en.html#x1-550007.1
https://www.tug.org/texlive/doc/texlive-en/texlive-en.html#x1-650007.2.2

Thus after adding or removing a path to the priority order we should also call

mktexlsr   

or possibly better

texhash