TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a LaTeX command that will allow me to insert pre-defined tables with a minimum of fuss. This will also allow me to change the overall format of tables (e.g. caption above or below) globally, without having to modify each instance.

Ideally, I am thinking something along the lines of \includetable{label}{caption}, where label corresponds to the float's label (for linking purposes), and caption corresponds to the caption displayed above (or below) the table. I would like to use label for the filename also, e.g. the table contents would be defined in label.tex.

The problem I have is that I use colons in my labels to distinguish tables, figures, and sections in a consistent manner. For example, a table relating to a structure's mass budget would have a label like t:structure:mass; in Windows, I cannot have colons in filenames, so I would like the function \includetable to replace colons with hyphens when calling \input.

The closest thing I've found on Stack Overflow is http://stackoverflow.com/questions/95824/replace-a-character-with-a-string-in-latex, but I can't get this to work with colons instead of commas. Suggestions?

share|improve this question

migrated from stackoverflow.com Nov 26 '11 at 20:14

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – Torbjørn T. Nov 26 '11 at 20:22
Do you tried the solution with the package xstring? – Marco Daniel Nov 26 '11 at 20:36

Some variations are possible. One can think, for example, to a key-value syntax for deciding the position of the caption and for providing a short caption.

share|improve this answer
The package is named xstring without the s. – Ludovic Kuty Jun 27 '12 at 13:00
@LudovicKuty Thanks! – egreg Jun 27 '12 at 13:10

To be compiled with luaTeX.


  10 & 20 \\
  20 & 40

        local s, _ = string.gsub("#1",":","-")


\includetable{t:mysection:mytable}{My table}

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.