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
108 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 ...
1
vote
1answer
41 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
10 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
54 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
81 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
56 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
189 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
34 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
80 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
405 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); %...
0
votes
0answers
29 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
298 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
914 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
64 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
33 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
88 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
35 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
67 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
72 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
42 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
233 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
43 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
28 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
91 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
503 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
32 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
133 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 ...
5
votes
1answer
69 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
72 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
66 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
171 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
31 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
58 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
57 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
105 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
88 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
34 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
63 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
91 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
41 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
92 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
82 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
64 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
107 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
32 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
214 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
128 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
32 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 ...
1
vote
1answer
115 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
180 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....