Questions tagged [programming]

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

Filter by
Sorted by
Tagged with
0
votes
4answers
77 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 ...
6
votes
3answers
368 views

Programmatically drawing sinusoids with tikz

Here are 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); %...
0
votes
0answers
28 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
255 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
882 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
61 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
30 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
80 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
34 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
64 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 ...
5
votes
2answers
65 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
37 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
215 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
40 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 ...
0
votes
0answers
24 views

How are pgf-keys stored and is it possible to print a list of them

I was wondering how pgf-keys are handled internally. For example: If I define: \pgfkeys{/A/.code={My Key}} and I call the key with Hello this is \pgfkeys{/A}. How does the \pgfkeys-command expand? ...
3
votes
2answers
87 views

keyval - function for keyB should act dependent on value of keyA - how to do this?

I'm new to LaTeX. I learn and I use article class. I struggle learning working with keyval package: I try to write macro \macro which only uses one mandatory argument where user can provide key value ...
8
votes
2answers
493 views

Mark command as obsolete

Is it possible to declare some command inside a package as obsolete? I work on a package and want to inform users that in the next version of the package this commands will be deleted. What kind of ...
2
votes
1answer
31 views

Reading an input word in an array and then processing character by character

For some application, I need to read input tex file word by word (not necessarily as arguments of any command), and then to print each word after changing the positions of some characters within the ...
7
votes
1answer
123 views

Does \expanded replace the \romannumeral trick for expansion?

TeXLive 2019 is here :D One of its awaited features is the new \expanded primitive now available in all of the main engines (only available in LuaTeX in previous years) thanks to Joseph Wright. What ...
4
votes
1answer
54 views

Changing a tcolorbox listing option based on the number of lines of its listing

Consider the following code which produces listings: % ---------------------------------------------------------------------------- % % Preamble \documentclass[12pt]{article} % -----------------------...
1
vote
1answer
61 views

Is there a way to define \xmat*{M}{n}{m} in the physics package

As titled, I want the command\mqty(\xmat*{M}{n}{m}) to generate a matrix like this: $$ \begin{pmatrix} M_{ 11 } & M_{ 12 } & M_{ 13 } & \cdots & M_{ 1m } \\ M_{...
2
votes
1answer
64 views

Dynamic row spacing if total character is variable

I use datatool to get data and row spacing can change. Count word/character of Total character of (Text A + Text B) if: Total charater of (Text A + Text B) < 20 characters => set row space of ...
6
votes
3answers
157 views

\numexpr behavior in math mode and/or TikZ

I am attempting to create a triangular grid of numbers like shown below: This was created in TikZ by hard-coding each point, but I would like to generate the grid procedurally so I can make ...
0
votes
0answers
29 views

LaTeX - Pass variable into a string [duplicate]

In LaTeX I am trying to pass a variable into a line for the \progressbar. If you type everything in it looks like this \progressbar[linecolor=blue, filledcolor=green]{.25} \begin{picture}(0,0)\put(-...
0
votes
0answers
54 views

Embedded picture with separate coordinate system (Tikz)

Am using Tikz, and have a slightly complicated drawing. Now I want to replace a rectangle in a certain place with a more sophisticated shape. This shape I have in SVG format, and I want to replace the ...
3
votes
1answer
52 views

Use array/list/sequence for repetitive code?

For a PhD thesis cover template in our university, there is some code as follow: %%% Jury member n1 (Président) %%% \newcommand{\jurynameA}{M. Cabot} \newcommand{\juryadressA}{Someplace} \newcommand{\...
2
votes
1answer
76 views

How to expand condition on \IfEqCase before evaluation?

I'm trying to do a simple task (as in the MWE below). When a given text is given (a filename) it outputs a given color. To work as I intended, \IfEqCase should only evaluate the file extension, as ...
2
votes
2answers
86 views

Know in which column am I in [closed]

it there a way to have a variable that returns in which column of my multicols environment am I in? Thanks!
0
votes
0answers
33 views

Is it possible to `\include`/`\input` a text depending on the language set on babel or polyglossia

I would like to know if it is possible to conditionally require, in a given document, the inclusion of a chapter or the input of a particular piece of text, depending on the language set on babel or ...
3
votes
2answers
54 views

Special treatment for first and last items in \seq_map_inline

It is rather common to have to apply special treatment for first and last items of a sequence. I wonder what the best ways to treat these cases in expl3's \seq_map_inline. For instance, suppose I'd ...
2
votes
2answers
89 views

How can I wrap this hard-coded image gallery into a new environment?

I'm building a gallery using tabularx and tikz, similar to image-gallery. Here's a snippet: \documentclass{article} \usepackage{tikz} ...
0
votes
0answers
39 views

Generalization of progressive downscaling of fontsize

Although the answers to How can I progressively scale letters? are functional in the restricted context of the post, I would like to extend it by asking for a programmatic solution to the more general ...
2
votes
1answer
89 views

Reflection in ConTeXt

The answer to ConTeXt: avoid enumeration items across pages was a nice introduction to modifying TeX before rendering, like HTML with JavaScript. \startsetups [userdata:itemize] \setbox\scratchbox\...
1
vote
1answer
71 views

Input variable as argument in metapost script?

I would like to pass input parameters into my .mp script. For example, instead of running: mpost script.mp I want to run something like: mpost script.mp 1 1 2 diamand Where "1 1 2 diamond" are 4 ...
2
votes
1answer
55 views

Extend book class with options of multiple values

I am writing a class based on book.cls, to which I want to have an option that is a list, so I can do \documentclass[languages={french, english}]{testops} I have define the key using l3key2e. But it ...
0
votes
1answer
92 views

Convert TeX to a standard equation string [closed]

I'm currently programming in Javascript, I figured this would be the best place to put it. I'm very very new to TeX, in fact I discovered it within the past hour. I was wondering if I could convert ...
2
votes
1answer
30 views

\centering leads to cascade of errors

Context: I'm developing a title page (writing my own titlepage environment) and I'm writing my own \thanks command (to give me control over where I spew the footnotes). Not knowing how \footnote does ...
3
votes
1answer
205 views

Processing a math paper written in TeX to generate a summary

I'm interested in writing a program that can automatically process math papers written in TeX in order to generate summaries. I have partly finished one written in Python but it does not seem to work ...
5
votes
2answers
124 views

Macro losing value when exiting custom environment

I'm trying to define my own custom environment, and ran into this problem: When I set a macro inside the environment's start code, that macro loses its value at the end of the environment. To be more ...
0
votes
1answer
31 views

Designing the programming list block in LyX

I'm new to LyX. I'm trying to create a programming block of some PL which looks like in the picture bellow: Tried to look for some similar threads, bud didn't find any. How can I make make the ...
0
votes
1answer
105 views

LaTeX error: illegal parameter number in definition of \pgffor@b

I am trying to use a loop. The following does not work: \foreach \a in {no,has}{ \begin{table}[H] \footnotesize \captionsetup{width=.9\linewidth} \caption{text} \vspace{-22pt} ...
3
votes
3answers
177 views

How to more efficiently get code like this?

I have a folder containing files like these, 2007.pdf 2007_Q1.pdf 2007_Q10.pdf ... 2007_Q5.pdf 2007_Q6.pdf 2007_Q7.pdf 2007_Q8.pdf 2007_Q9.pdf 2008.pdf 2008_Q1.pdf 2008_Q10.pdf 2008_Q11.pdf 2008_Q12....
2
votes
1answer
70 views

How to rewrite the looping below with nested ifelse operators?

Could you rewrite the looping part just with nested PostScript ifelse operators? \documentclass[pstricks,border=1cm]{standalone} \makeatletter \def\scale{% \psline(100,0) \foreach \x in {0,...
4
votes
2answers
366 views

“Incomplete \ifcase” error depends not on the \ifcase but the integer at which it's evaluated

I have a puzzling Incomplete \ifcase; all text was ignored after… error in that the same \ifcase is fine if I evaluate it at the largest integer for which it's defined, but if I evaluate it at a ...
4
votes
1answer
170 views

How can I change the number of iterations from 11 to 3?

The simplified example given below currently uses 11 iterations just for drawing at most 3 stems (vertical segments). It seems that my code is not efficient enough so I want to reduce the number of ...
2
votes
1answer
46 views

Why does arrayjobx return the wrong elements of the bi-dimensional matrix I defined?

In the following MWE, I use package arrayjobx to define a 2x3 array \RowPayoffs, where I assign each element its value by referencing its (row, column). Specifically, I define \RowPayoffs(i,j)={Rij}, ...
3
votes
0answers
47 views

Efficiently setting category code for a range of characters

I kept thinking about using Cyrillic characters in command names with PDFTeX engine. It looks to me so far that if I stay with 8-bit encoding and assign category code 11 to all Cyrillic letters ...
1
vote
2answers
683 views

Node above other node fails with “cannot parse this coordinate”

I'm Alex stuying automation engineering and have to write my master thesis with tex. Until now, I haven't really used tikz or used a program to draw graphics and exported them to tikz. Now for the ...
1
vote
1answer
97 views

Save command result in other command

I am getting a value by a command. Now I am temporarily changing a saved variable which changes the command output. After I finished some code I want to reset the stored value if the value before the ...
1
vote
0answers
54 views

Processing latex? Ie get text bounding boxs etc

Im looking at the possibility of processing a latex document to get coordinates of element off the page. For example if I want to get the coordinates of an image, or a heading off a page and output ...