Questions tagged [programming]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
40 views

How to make a frame for a single page in landscape programatically for letter and A4?

I recently completed running an international conference. I hope to make certificates in a landscape orientation for the organizing committee, and some other attendees. In order to make everything ...
14
votes
4answers
1k views

Converting mathematical TeX expressions

Is there a (hopefully simple) way to convert a mathematical TeX expression, such as \frac{\cos(x^2) - x}{x^2 + 1}, to expressions which you would use in a programming language? The outcome of the ...
6
votes
2answers
574 views

Equational Reasoning for Functional Programming

How can I create equational reasoning proof like the ones in CS literatures: A + (B + C) = { Associativity } (A + B) + C = { Commutativity } (B + A) + C I can't seem to find the right ...
2
votes
0answers
22 views

Keyword lists for OpenMP and OpenACC for listings

Has anybody produced a dialect for the C, C++, and Fortran languages in the listings package to highlight OpenMP and OpenACC directives in code that include these pragmas (C/C++) or sentinels (Fortran)...
1
vote
1answer
42 views

conditional operator if in latex

It is necessary to build a graph (vector diagram of a diode) and if the angle (\ Fi) is greater than 90, then all vectors will be equal to 0. I don’t understand how to use if in latex correctly. \ ...
0
votes
0answers
236 views

Latex for telegram whatsapps and email

In the site of Quora we can write mathematics formulas with latex codes. It converts automatically the codes to Math. formulas. can one do the same in "telegram", Whatsapp. or emails ...
4
votes
4answers
704 views

Theoretical/academical question - Is it possible to simulate, e.g., a (unicode) LuaTeX engine on an 8-bit Knuth TeX engine?

The following questions are rather theoretical/academical in nature. According to Wikipedia a system of data-manipulation rules (such as a computer's instruction set, a programming language, or a ...
2
votes
1answer
64 views

Macros that can scan the contents of their arguments

I was thinking that it since the architecture of LaTeX is a collection of pre-processors on top of TeX, that it may be possible that some macros could in theory do some sort of find-and-replace within ...
1
vote
3answers
106 views

Generate table using formula

What is the simplest most universal way to generate a table using a formula? Minimal amount of code that is most robust. I simply want to essentially generate a table of values where the values are ...
11
votes
1answer
1k views

How to write a real “Hello World” program

One of the easiest tasks in almost all programming languages is to write a program that writes "Hello World" into the terminal. Something similar in TeX is: tex '\empty Hello world! \bye' ...
0
votes
0answers
33 views

The adjacency list for page looks a lot like in latex

How to represent the following in latex
1
vote
0answers
27 views

How to check if some macro defined via \csname is empty?

I need to check whether my macro \csname creator1\endcsname empty or not. But I always get 1(not empty) \documentclass[]{article} \makeatletter \newcommand{\creator}[1]{% \expandafter\def\csname ...
0
votes
0answers
60 views

“Situation management” in LaTeX / expl3?

It happens from time to time that I would like to implement LaTeX commands that behave differently depending on the situation. E.g., a command that returns different compositions of tokens depending ...
4
votes
1answer
107 views

How to understand correctly scope of local variable in LaTeX3?

Common programming languages (C). // foo is global scope int foo = 0; int main() { // bar is local scope within main int bar = 1; } Let's consider LaTeX3 \documentclass[]{article} \...
1
vote
1answer
90 views

Why doesn’t TeX allow local, expandable definitions inside commands?

Half of the pain of programming TeX is the difference between expandable and non-expandable commands, the latter usually being a result of an assignment taking place inside the command definition. ...
3
votes
1answer
119 views

How to ignore contents of an environment imported from another file?

Consider the following scenario: I define a package mypac.sty as follows % mypac.sty \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{mypac}[2020/10/08 v0.01 LaTeX package for my own purpose] ...
1
vote
1answer
84 views

Help to make a faster token replacing macro

I have a macro called \logic which helps me write logical formulas faster by simplifying some common logical symbols. So when I write $\logic{p -> q}$ I obtain $p \to q$. Here's the code: \...
0
votes
2answers
48 views

How do i force \pagebreak on everything in LaTeX

I would like to learn how to force a page break on everything that goes over the page. Suppose I have a document that involves multiple images, paragraphs, figures connected to paragraphs and lists. ...
5
votes
4answers
390 views

How to command LaTeX to treat a non-value as 0

I have this command \newcommand{\lines}[1]{\multido{}{#1}{\vskip 5mm \makebox[\linewidth]{\dotfill}} \vskip 8mm\setlength{\rightmargin}{5em}} It allows me to create dotted lines with ease. For ...
1
vote
2answers
99 views

How to make red for every 3n-2 item of enumerate items?

I want to automatically make red for every item with remainder of 1 when divided by 3. Manually wrapping the 3n-2 items with \textcolor{} will be an absurd idea especially in the current AI era. MWE \...
0
votes
0answers
44 views

Specifying pgf/tikz Inputs with a Different Language

What I'd like to be able to do is say something like \begin{tikzpicture} \begin{axis} \addplot+[only marks] coordinates { <Entirely Different Language> }; \end{axis} \end{...
1
vote
1answer
57 views

Dynamic table : setting the column number after the table

I would like to create a dynamic table with \N columns at the beginning of the page, in which \N is the number of sections in the whole document, so the value of \N is set after the table. When I set ...
1
vote
2answers
98 views

Add newline after every period in the document

Is there a way to make every period (dot) act like \newline command ? The only way I can think of now is to write shell-script to do it for me.
0
votes
0answers
35 views

where to find the best resource and support for tikz or latex developer? [duplicate]

I want to learn the latex coding for which i have searched multiple resource over the internet but did not got much of the idea and found very few resources over the internet about tikz or latex. so I ...
9
votes
3answers
371 views

How to dynamically create a cumulative score table with hyperlinks?

Scenario I want to bundle students' homeworks in a single PDF. The students submit their works in PNG and I grade them. Each homework is separated by a folder indicating the DueDate. For example, for ...
2
votes
1answer
22 views

Optional savebox with options

I'm working on a modified version of the report.cls for internal documents that might have a standard disclaimer text included. Ideally, I'd like to have something like \disclaimer{some category}{...
1
vote
1answer
40 views

How add new argument to command to control scaling?

The following code, slightly modified from https://tex.stackexchange.com/a/552769/13492, allows creating new symbols \bigplus, \bigtimes, and \bigbox. However, it hard-codes the scaling factor \...
1
vote
2answers
36 views

Indirect control of behavior: how do I lengthen some pages and not others?

I'd like to be able to control the behavior of latex indirectly. Let me try to explain what I mean. I've got a large document, generated by a program. We can assume that each page (or page group) ...
0
votes
2answers
177 views

Can TeX be used in programming?

I heard that TeX is a Turing complete language. Does it mean that one can use TeX for example to write operating systems or games like Tetris or Hangman? I don't mean that one writes a source code of ...
1
vote
1answer
31 views

Command works as “\csname cmd \endcsname” but not as “\cmd”

I'm trying to create a command (\dummy) for dynamic macro definition. It is supposed to return a macro that is named dynamically (#3) with the content of #2 concatenated after #1 iterations. \...
0
votes
0answers
33 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} \...
13
votes
2answers
607 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 the code below has some ...
0
votes
1answer
34 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
33 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
48 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
47 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
307 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 ...
2
votes
1answer
85 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
1answer
141 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
181 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
22 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
105 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
57 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
80 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
69 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
44 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
114 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
355 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
861 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
62 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 ...

1
2 3 4 5
12