Questions tagged [programming]

{programming} is about how (La)TeX can be used as a programming language.

Filter by
Sorted by
Tagged with
0
votes
0answers
23 views

Is there a way to create a dynamic newcolumtype?

Is there a way to create a dynamic newcolumtype within e.g. a \newcommand such as \newcolumntype{#1}{m{50pt}}? I tried to do something like this : \documentclass{scrartcl} \usepackage{tabularx} \...
11
votes
2answers
536 views

Fun titles by splitting in letters (or words)

I want to display titles using a spelling routine I have found in this interesting discussion. The idea is that different simple effects can be easily selected. Unfortunately this code has some ...
0
votes
1answer
30 views

Best way to define an object with a list

The idea is to define objects like circles, or triangles with a list. I made this : \documentclass{article} \usepackage{xparse,tikz} \usetikzlibrary{through} \ExplSyntaxOn \NewDocumentCommand{\...
2
votes
1answer
28 views

Apply special formatting to capital letters in expl3

In my attempt to learn expl3 programming, I've hacked together a function to fake "smallcaps" by looping through a token list and enlarging any tokens that are capital letters. The code currently "...
0
votes
1answer
41 views

Switching driver after first citation

I need to tell LaTeX when citing an Incollection related to a Collection via crossref: if this is not the first citation of that collection, then use this driver instead of the usual one. Is that ...
1
vote
1answer
44 views

How to use integer from one command into another?

I have following way to get number of spaces in a string \ExplSyntaxOn \NewDocumentCommand{\HowManySpaces}{ m }{ \seq_set_split:Nnn \l_tmpa_seq { } { #1 } \int_eval:n {(\seq_count:N \l_tmpa_seq) ...
0
votes
1answer
22 views

Prevent multirow cell overflow with dynamic cell content

I have the following table layout: The table consists of 3 columns - one column which is 25% wide, and two columns that take up equal amounts of the space left (thus 37.5% each). The content for ...
0
votes
0answers
16 views

How can I write ASM and C listings and look like as MPLAB shows?

I'm writing a report on latex and I find difficult to set a language style for ASM e C language. I would like to set like as shows on MPLAB (see the photo). The actual code doesn't work so well. So I'...
2
votes
1answer
38 views

Invoking functions indirectly (using a string) in BibTeX

Is it possible to do indirect function calls in BibTeX styles, i.e. to get the function name from a field in the .bib? EXECUTE would be able to do that but these statements don't work within functions(...
0
votes
0answers
46 views

How to index table cells?

I have a table. I need to put some value (of a counter) in it cell and apply some format to cell depending on position of cell. For this reasons I need a indexing a cell. I was used code for ...
2
votes
2answers
155 views

How to use \csname\endcsname in LaTeX3 way?

I have some part or code made in LaTeX2e way. I been to rewrite it in LaTeX3 way, but I have no idea how to do this. More expanation in MWE \documentclass[]{article} \usepackage{xparse} \newcounter{...
0
votes
0answers
19 views

How can I create Local commands definitions in equations?

I would like to use small local macro expansion similar to how \newcommand works but on a per environment basis. Something that would expand \[ \begin{local} \local{\poly}[2][x]{#1^2 - #1^#2} \...
2
votes
2answers
75 views

\input a file that exists either in “./” or in “./figures”

I use XFig to draw most of my figures (how old am I?) and I find convenient to export in "LaTeX+PDF" format, in which a simple LaTeX source. e.g., fig03.pdf_t (the extension is fixed), is created. ...
2
votes
1answer
45 views

Counting values by a 0.5 step before drawing an histogram

In this question, I asked how to draw an histogram showing the repartition of the marks of my students. In the following example, I would like a have a more precise picture: a bar for student whose ...
2
votes
1answer
67 views

Metapost plotting B-Spline recursive formula gives strange results

I am currently trying to make a general B spline basis plotter with meta post. The definition of a basis function is on wikipedia under properties. The knots of a b spline should have the pattern ...
1
vote
1answer
51 views

Metapost how can you return values in a recursive function?

I am trying to code the recursive definition of B splines but I am stuck writing the recursion, my code won't compile because I am trying to assign "vacuous to numeric", According to online resources,...
1
vote
1answer
39 views

Convert string to one character with a hash table

I have a report where I mention some people. Sometimes I want to hide the real name of these people. I would like to write a macro that converts the name to a single character. \name{John Doe} ...
2
votes
3answers
103 views

Computing the mean value in (La)TeX

I have a list of marks included in a .tex document, with the begin{filecontents*} command. So far, I draw a histogram of the frequencies of the marks. I would like to add the mean value. Can you ...
3
votes
2answers
211 views

How to check a boolean argument in a command with optional arguments?

I have a command with an optional argument, and I want to execute some code depending if argument is true or false (I am sure that this command will have always some argument convertible to a boolean, ...
14
votes
4answers
776 views

How to get the sum, difference, product, and quotient from a macro in ConTeXt or Plain TeX?

I want to create a set of macros like this: \addnumbers{2}{5} \subtractnumbers{3}{5} \multiplynumbers{2}{-2} \dividenumbers{2}{8} The first will display the number 7, adding #1 and #2. The ...
1
vote
1answer
50 views

Drawing an histogram of the repartition of a data set

I have a dataset of marks (0 to 20), for example a [2, 3, 7, 14, 15, ...] I would like to draw an histogram of the repartition of this dataset. What I mean is an histogram where on the x-axis are ...
6
votes
1answer
92 views

Debugging of expl3 code

I've been programming quite a bit in expl3 for the last weeks, and while I really like the expressiveness of the provided API, what often is incredibly painful is debugging larger programs. In many ...
6
votes
1answer
165 views

How to time code execution in TeX?

Throughout time, during my conversations with members of TeX Exchange, I ran across a few ways to time execution of the code. But the pieces of this information are scattered throughout my account's ...
2
votes
1answer
87 views

LaTeX3 equivalent of C enumeration type

I'm having to store a non-binary status, what would be the more idiomatic LaTeX3 way of doing it? For instance, suppose that there are 3 possible ways to format a manuscript: long/short/medium. What ...
0
votes
2answers
158 views

automating recursive file hierarchy (directory tree) diagrams with tikz

So, I've been trying to write a python script that will produce the TikZ/LaTeX source code for one of these filesystem tree / directory structure diagrams: Preview Code LaTeX: TikZ \...
2
votes
1answer
99 views

Number formatting in PythonTeX with `sage` family

I am trying to get a special number formatting in pythontex with sage family but it doesn't work. Here is an example which shows how it should look like and what I tried so far. How can I make it ...
0
votes
1answer
51 views

How can I customize the latex output?

Assume I have prepared a CV, which has a section for my contact. For my webpage, I would like to have only my email in the contact section, for my job applications, I want to have my cell phone number ...
2
votes
2answers
26 views

Reset counter used program line

I have a problem with how to reset the counter in a case where I am trying to print names in one row and the telephone numbers in another row. I know I could have avoided the problem, but it is ...
0
votes
0answers
109 views

Tex for IT professionals [duplicate]

I'm working as a programmer for about 20 years and invested a lot of time into understanding programming and computers before earning money with it. I've learned to program Java, use Windows, then ...
3
votes
2answers
80 views

modifying default tabular behaviour

I basically do all my tables the same way: Is it possible to make tabular automate the \toprule, \midrule, \bottomrule and \hdashlines? \documentclass{article} \usepackage{booktabs,array,arydshln} \...
1
vote
0answers
14 views

Conditioning comments [duplicate]

I'm trying to condition comments. I got some information about if/else structures in Latex and here is my first idea : \newcounter{student} \setcounter{student}{1} \ifnum \value{student}=1 {\begin{...
3
votes
1answer
97 views

How can I use arrays in a PGF axis environment?

I would like to use an array in a PGF axis environment. This array would have the parameters values of a function to be plotted. I tried writing the following code: \documentclass{standalone} \...
4
votes
1answer
86 views

What would be the drawbacks of adding #0 for denoting the name of the macro that currently is expanded?

Assume a scenario where some macro triggers error-messages. The error-messages shall also reveal the name of the macro which did trigger the error-message. One could do something like this: \...
0
votes
2answers
67 views

how to write this this long equation?

\begin{align}\nonumber (A_{1}^{5}+A_{8}^2)\tt_{m}^{2}\k^{2}P_{m}^{5}-\left(2(A_{1}^{2}+A_{2}^2) (\Delta_{a}-\omega_{m}\chi^{2}C)\omega_{m}\chi^{2}-2J^{2}\omega_{m}\chi^{2} (\kappa_{a}A_{2}-\Delta_{d}...
6
votes
2answers
341 views

Macro for Automating Truth Tables

I used this truth table when writing a proof. Unfortunately I made a tiny typo; The first time around, I misplaced an additional ʹ symbol, which just happened to make the output exactly wrong. It ...
0
votes
1answer
84 views

Creating a global variable to toggle (show/hide) a bunch of answer keys

I have a bunch of simple trigonometric questions for warming up. Could you make a global variable \showAnswer that accepts true or false (default) to show and hide the answer? I prefer TeX solution ...
0
votes
4answers
94 views

How to define a macro that takes the definition of a macro as an argument

We would like to define a macro \ellipsis that takes four argument and has the following behaviour: \ellipsis{x^{#DUMMY#}}{0}{5}{+} and outputs: the pattern string #DUMMY# (which doesn't have to be ...
9
votes
3answers
608 views

programmatically drawing sinusoids with tikz

Here's eight full oscillations of a sine wave: Here's the code: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[gray!20] (0,-2) grid (32,2); %...
1
vote
1answer
42 views

Define a `\newenvironment` that stores its content in a token register or in a macro

In the code below I want to define a new environment that stores its contents in order to use it later several times with different formats \documentclass{article} \newtoks\environmentcontents \...
14
votes
2answers
697 views

Drawing an accurate guitar fretboard with TikZ

This is kind of a fun one. dist( x ) = s / ( 2 ^ ( x / d ) ) Such that: x = number of the fret being evaluated (let's say {0,...,24} so it's exactly 2 full octaves). s = scale length (...
9
votes
2answers
1k views

Programmatically Illustrating Permutations

Here's an illustration of what's known as an expansion permutation (the top half). It just means that instead of going straight through (like the bottom half aka. the identity permutation), the signal ...
1
vote
1answer
68 views

writing functions and wrapping commands for abstraction

Can i write a little function (or macro or whatever) that wraps two commands (functions?) into one; united under a single alias? Specifically I want to wrap \input{} and \includegraphics{} into a ...
0
votes
1answer
37 views

Automatically generate table with content from different environments

I am using a very simple custom environment to create exercises and their solutions. Each exercise yields a individual number of points. The number of points is defined in this way: % First argument: ...
0
votes
2answers
97 views

Import photos directly from a folder [closed]

I just want to automate a report, but i have to add photos from a folder one after the other (all with the same termination(.jpg)), is there a macro or something that adds all the photos at once? For ...
0
votes
0answers
37 views

foreach looping error [duplicate]

Prior to posting this question, I have read the post here: OP asks the same question two or three times or does the same strange things several times My purpose in asking same questions with ...
1
vote
0answers
80 views

Tikz language syntax

I'm hoping to add a tikz-specific language environment to my LaTeX editor (vscode), I've run into a bit of an issue looking for any speicifications for tikz grammar though. Would anybody know of any ...
6
votes
2answers
97 views

Checking if argument is a floating point without breaking on control sequences in argument

Inspired by this answer to test whether an argument is a positive integer, I would like to extend this to floating point numbers. I want to have a macro \TestNumber that checks, whether its first ...
1
vote
1answer
55 views

LaTeX code with input dependent on some integer parameters

Suppose that I have a large number of .tex files with names 1.tex, 2.tex, ..., N.tex (with N = some integer). I would like to write a LaTeX document, where I set some parameters for example: howMany ...
10
votes
3answers
331 views

Smart-expansion of a range to a list of numbers

I am wondering if there is a simple way to expand some input text such as "3-7" as "3,4,5,6,7"? For context, I am using \foreach and want to be able to write \foreach \x in {3-7, 9, 14, 52} and ...
2
votes
0answers
198 views

An Automatic Way to Produce “Author Contribution” Section

Background Academic journals and other scholarly publications are beginning to adopt a standardized requirement for Author Contribution sections. This is a section in which authors are labeled based ...

1
2 3 4 5
11