Questions tagged [programming]

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

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

Framework for interactive graphics in LaTeX documents

I've written a prototype LaTeX package and associated viewing framework to allow LaTeX documents to be viewed in an environment that allows for interaction with figures. The figure might have points ...
user avatar
0 votes
1 answer
30 views

Getting a chapter number value for comparing

I'm trying to compare a chapter number like this: \newcounter{exerciseChapterCounter} \newcounter{exerciseChapterCounter} \newcounter{exerciseQuestionCounter} \setcounter{exerciseChapterCounter}{1} \...
user avatar
3 votes
1 answer
75 views

Space oddity: are there spaces that won't end up on the page?

I think the answer to my question is "no," but one could argue that it would be nice if there were. Here's what motivates the question. Define \def\myloop#1#2{\count11=#1#2% \advance\count11 ...
user avatar
8 votes
2 answers
490 views

Parsing oddity: when is a space not a space

Saying \count89=14 \the\count89~{\count89=11 \the\count89~}\the\count89 produces 14 11 14, as one would expect. But, get rid of the space in the middle clause: \count89=14 \the\count89~{\count89=11\...
user avatar
2 votes
0 answers
116 views

TeX as a programming language: examples and design patterns

I'm looking for simple examples of using TeX as a programming language, not LaTeX, and ideally these examples only use the primitive TeX commands. Why? Because the members of a local computer club ...
user avatar
1 vote
1 answer
35 views

Latex .tex file input highlighted, listed, code

I have the latex document: \begin{document} Document introduction. \onecolumn \section*{That's how the code looks like} \begin{algorithm} \input{z.tex} \begin{algorithm} \end{document} And I ...
user avatar
2 votes
2 answers
90 views

Multi language text

I am writing my CV with LaTeX, right now I have the code below that I use to create two commands \eng{} and \ita{} that allows me to hide text in the language I do not want. %% English %% \newtoggle{...
user avatar
1 vote
1 answer
71 views

TeX \ifx conditional not working for string comparison

I would like a LaTeX source file to compile in different ways depending on the job name. However, when I run pdflatex mwe with mwe.tex containing \documentclass{article} \begin{document} \ifx{mwe}\...
user avatar
  • 69
0 votes
0 answers
89 views

lstlisting collection of styles

I'm looking for a collection of different styles for the lstlisting package. I know there are some good ones for examples of tikz pictures and templates, but I couldn't find one for lstlistings. Does ...
user avatar
  • 366
1 vote
1 answer
69 views

Blackout censor macro capable of handling italic and bold fonts

In the following TeX stackexchange answer, the author provides an excellent \blackout macro that produces very aesthetically pleasing underline effect. However, this macro does not work well with any ...
user avatar
1 vote
1 answer
40 views

Use macro to create array column specification

How can I make a custom macro that creates an array with some number of columns, but I'm having trouble forcing the macro to expand inline. In test.sty: \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{test} ...
user avatar
0 votes
2 answers
162 views

Can I "program" TeX using C/C++? [closed]

I have a fairly complicated TeX programming (not typesetting) task, and I've skimmed the manual on TeX programming. However, TeX's... clunky programming syntax is less than ideal, and I'm wondering if ...
user avatar
7 votes
3 answers
1k views

Base64 encoding in LaTeX?

How can we encode some text/string using Base64 encoding in LaTeX? or any alternative solution? For example, the Base64 encoding of string Latex is bGF0ZXg=. Here's a representation of what I want to ...
user avatar
  • 147
31 votes
6 answers
4k views

What is the programming paradigm of TeX language?

From a considerable time, I am asking to myself how TeX language is classified. I have looked for some useful information in Internet a couple of times without success (even a tip!). In this list (...
user avatar
2 votes
1 answer
33 views

Modifying a list and passing it to another command

I am trying to write some macros to easy my life while writing mathematics in LaTeX. For this, I would like to have some macros to write wedge products in a more concise manner. I have a command which ...
user avatar
1 vote
1 answer
53 views

Using csdef in table

I am trying to automatically add a decision summary when writing meeting minutes. For each paragraph of the meeting I use a table to organize the paragraph number, name and content, and I use etoolbox ...
user avatar
  • 13
0 votes
1 answer
78 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 ...
user avatar
  • 295
14 votes
4 answers
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 ...
user avatar
  • 151
6 votes
2 answers
670 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 ...
user avatar
2 votes
0 answers
43 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)...
user avatar
  • 173
1 vote
1 answer
97 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. \ ...
user avatar
0 votes
0 answers
729 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 ...
user avatar
4 votes
4 answers
719 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 ...
user avatar
2 votes
1 answer
70 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 ...
user avatar
1 vote
3 answers
137 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 ...
user avatar
  • 143
11 votes
1 answer
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' ...
user avatar
  • 359
1 vote
0 answers
39 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 ...
user avatar
  • 4,932
0 votes
0 answers
69 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 ...
user avatar
4 votes
1 answer
131 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} \...
user avatar
  • 4,932
1 vote
1 answer
99 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. ...
user avatar
  • 10.9k
3 votes
1 answer
129 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] ...
user avatar
1 vote
1 answer
114 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: \...
user avatar
  • 3,251
0 votes
2 answers
113 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. ...
user avatar
5 votes
4 answers
414 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 ...
user avatar
1 vote
2 answers
125 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 \...
user avatar
0 votes
0 answers
56 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{...
user avatar
1 vote
1 answer
71 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 ...
user avatar
  • 85
2 votes
2 answers
240 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.
user avatar
9 votes
3 answers
405 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 ...
user avatar
2 votes
1 answer
30 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}{...
user avatar
2 votes
1 answer
73 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 \...
user avatar
  • 6,382
1 vote
2 answers
42 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) ...
user avatar
  • 447
1 vote
2 answers
380 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 ...
user avatar
  • 13
1 vote
1 answer
43 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. \...
user avatar
  • 167
0 votes
0 answers
39 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} \...
user avatar
  • 167
13 votes
2 answers
633 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 ...
user avatar
  • 768
0 votes
1 answer
43 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{\...
user avatar
2 votes
1 answer
38 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 "...
user avatar
0 votes
1 answer
54 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 ...
user avatar
  • 557
1 vote
1 answer
50 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) ...
user avatar
  • 167

1
2 3 4 5
12