add tag
निरंजन
Suppose I have a `build.lua`, a `foo.dtx` and a `foo.ins` with the directory structure as this:

```
.
├── build.lua
├── foo.dtx
└── foo.ins
```

and the the contents as follows:

### `build.lua`

```
module = "foo"
```

### `foo.dtx`

```
%    \begin{macrocode}
%<*pkg>
\def\foo{foo}
%</pkg>
%    \end{macrocode}
%    \begin{macrocode}
%<*def>
\def\foo{foo}
%</def>
%    \end{macrocode}
```

### `foo.ins`

```#
\input l3docstrip.tex
\usedir{tex/latex/\jobname}
\generate{%
  \file{\jobname.sty}{\from{\jobname.dtx}{pkg}}%
}
\usedir{tex/latex/\jobname/def}
\generate{%
  \file{\jobname.def}{\from{\jobname.dtx}{def}}%
}
\endbatchfile
```

I am facing difficulty in understanding the following:

1. When I run `latex foo.ins`, my directory looks like:
   ```
   .
   ├── foo.def
   ├── foo.dtx
   ├── foo.ins
   └── foo.sty
   ```
   (Note that I skipped `build.lua` and `foo.log` as they were irrelevant.)
   
   I don't understand the role of `\usedir{tex/latex/\jobname/def}` in this case. When I specifically mention the path (`./def` in this case, see line number 6 from the ins file) in which I want to see a particular file (`foo.def` in this case), why is the non-existent path not created? I expect the path to be created and the then the specific file to be generated there. Instead, the file is installed in the same directory where the .sty is generated. To me, this seems quite counter intuitive. 
1. When I run `l3build install`, what all from the `.ins` file is relevant? If the content of the `.ins` file is relevant, then maybe fixing 1 would solve the issue for `l3build` too, but suppose it isn't, then the question is how do I instruct `l3build` to create the structure I need. I tried adding the following to `build.lua` with no success.
   ```
   maindir = "."
   texmfdir = maindir .. "def/"
   sourcefiles = { "*.def","*.sty","*.dtx","*.ins" }
   installfiles = sourcefiles
   ```
   This creates all the necessary files in the `build/` directory as well as in the `texmf/` directory, but still the desired directory structure is not obtained. At the end everything is boiled down to a flat structure which I don't want.
1. Along with `latex foo.ins` and `l3build install`, I also want my regression testing to work with the new directory structure. So how do I set things up for that? Also, if I create a CTAN zip with `l3build ctan`, that should also produce the correct directory structure.
Top Answer
Joseph Wright
The DocStrip approach with `\usedir` requires quite a bit of 'local' setup, in particular

> The important thing to note here is that it is impossible to create a new
directory from inside TeX. So however you configure DocStrip, you need to create
all needed directories before running the installation. Authors may want to begin
every installation script by displaying a list of directories that will be used and
asking user if he’s sure all of them exist.

It also needs you to set the `\BaseDirectory` and so on - in other words, it was not designed to work in a portable way but rather to be set up by a 'local expert' for multi-user installations in a 1980s/early 1990s model.

As such, `l3build` works entirely independently of the 'installation targets' in the `.ins` file. Files are installed by default using standard TDS locations, e.g. `.sty` files go in `tex/latex/<pkg>/`. You can override this using `tdslocations`:
```lua
tdslocations =
  {
    "tex/latex/mymodule/config/*.def",
    "tex/latex/mymodule/includes/*.xyz"
  }
```
etc. As this is 'just Lua', you can if required build up the list programmatically, use other variables, etc.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.