AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[templates](coding)

Martin Hope
Sam
Asked: 2024-12-28 00:25:45 +0800 CST

将图像添加到 LaTeX 中预制的投影仪中

  • 6

我想使用一个名为 Argüelles 的 beamer 模板(https://github.com/piazzai/arguelles/?tab=readme-ov-file)并在标题页中添加图片。标题页的定义是:

% title page
\defbeamertemplate*{title page}{Arguelles}{
  \vfill\begin{beamercolorbox}{inverted text}
    {\usebeamerfont{title}\inserttitle}\par
    {\usebeamerfont{subtitle}\insertsubtitle}\par\bigskip
    {\usebeamerfont{event}\insertevent}\par
    {\usebeamerfont{date}\insertdate}\par\bigskip
    {\usebeamerfont{author}\insertauthor}\par\smallskip
    {\usebeamerfont{institute}\insertinstitute}\par
    {\usebeamerfont{email}\insertemail}\par
    {\usebeamerfont{homepage}\inserthomepage}\par
    {\usebeamerfont{github}\insertgithub}
  \end{beamercolorbox}
  \addtocounter{framenumber}{-1}
}

我们使用它:

\begin{document}
\frame[plain]{\titlepage}

所以我认为添加 tikz 包并直接在模板文件中添加图片会起作用,但我不知道为什么它不起作用:

  \end{beamercolorbox}
  \begin{tikzpicture}[remember picture,overlay]
  \node[anchor=south east, xshift=-0.5cm, yshift=0.5cm] at (current page.south east) {
    \includegraphics[width=2cm]{obs.png}
  };
  \addtocounter{framenumber}{-1}

否则,我不知道是否可以直接在我的.tex 文件上执行此操作...

谢谢 !

这是一个可编译的示例:

\documentclass[compress,12pt]{beamer}

\usetheme{Arguelles}

\title{Argüelles}
\subtitle{Simple, typographic beamer theme}
\event{}
\date{}
\author{Place Holder}
\institute{University of \TeX}
\email{[email protected]}
\homepage{www.mywebsite.com}
\github{username}

\begin{document}

\frame[plain]{\titlepage}

\Section{Demo}

\begin{frame}
      \frametitle{A frame with title and subtitle}
      \framesubtitle{Subtitle here}
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua \par
      Itemized list:
      \begin{itemize}
            \item Lorem ipsum
            \item Dolor sit amet
                  \begin{itemize}
                        \item Consectetur
                        \item Adipiscing elit
                  \end{itemize}
            \item Sed do eiusmod
                  \begin{itemize}
                        \item Tempor incididunt
                              \begin{itemize}
                                    \item Ut labore et dolore
                                    \item Magna aliqua
                              \end{itemize}
                  \end{itemize}
      \end{itemize}
\end{frame}
\end{document}
templates
  • 1 个回答
  • 13 Views
Martin Hope
Abel Siqueira
Asked: 2024-09-12 19:36:12 +0800 CST

在 Jinja 中删除空行并且不连接非空行

  • 6

我想让以下徽章列表看起来美观一些:

Badge
{% if cond %}Other badge {% endif %}
Another badge
{% if not cond %}One more badge {% endif %}
Last badge

我希望:

  • 每个徽章都有自己的系列
  • 如果没有添加徽章,则不要添加空行

我尝试了 16 种添加或分隔符的组合-,{%但%}无法同时实现这两项功能。

更多详细信息:

  • 我有一份条件徽章列表
  • 上面的例子是一个简化版本cond,not cond同时具有,因此问题始终存在
  • 实际上,我没有if-else 的情况,它只适用于MRE
  • 这 16 种组合是
    Badge (-,-,-,-)
    {%- if cond -%}Other badge {%- endif -%}
    Another badge
    {%- if not cond -%}One more badge {%- endif -%}
    Last badge
    
    Badge (,-,-,-)
    {% if cond -%}Other badge {%- endif -%}
    Another badge
    {% if not cond -%}One more badge {%- endif -%}
    Last badge
    
    Badge (-,,-,-)
    {%- if cond %}Other badge {%- endif -%}
    Another badge
    {%- if not cond %}One more badge {%- endif -%}
    Last badge
    
    Badge (,,-,-)
    {% if cond %}Other badge {%- endif -%}
    Another badge
    {% if not cond %}One more badge {%- endif -%}
    Last badge
    
    Badge (-,-,,-)
    {%- if cond -%}Other badge {% endif -%}
    Another badge
    {%- if not cond -%}One more badge {% endif -%}
    Last badge
    
    Badge (,-,,-)
    {% if cond -%}Other badge {% endif -%}
    Another badge
    {% if not cond -%}One more badge {% endif -%}
    Last badge
    
    Badge (-,,,-)
    {%- if cond %}Other badge {% endif -%}
    Another badge
    {%- if not cond %}One more badge {% endif -%}
    Last badge
    
    Badge (,,,-)
    {% if cond %}Other badge {% endif -%}
    Another badge
    {% if not cond %}One more badge {% endif -%}
    Last badge
    
    Badge (-,-,-,)
    {%- if cond -%}Other badge {%- endif %}
    Another badge
    {%- if not cond -%}One more badge {%- endif %}
    Last badge
    
    Badge (,-,-,)
    {% if cond -%}Other badge {%- endif %}
    Another badge
    {% if not cond -%}One more badge {%- endif %}
    Last badge
    
    Badge (-,,-,)
    {%- if cond %}Other badge {%- endif %}
    Another badge
    {%- if not cond %}One more badge {%- endif %}
    Last badge
    
    Badge (,,-,)
    {% if cond %}Other badge {%- endif %}
    Another badge
    {% if not cond %}One more badge {%- endif %}
    Last badge
    
    Badge (-,-,,)
    {%- if cond -%}Other badge {% endif %}
    Another badge
    {%- if not cond -%}One more badge {% endif %}
    Last badge
    
    Badge (,-,,)
    {% if cond -%}Other badge {% endif %}
    Another badge
    {% if not cond -%}One more badge {% endif %}
    Last badge
    
    Badge (-,,,)
    {%- if cond %}Other badge {% endif %}
    Another badge
    {%- if not cond %}One more badge {% endif %}
    Last badge
    
    Badge (,,,)
    {% if cond %}Other badge {% endif %}
    Another badge
    {% if not cond %}One more badge {% endif %}
    Last badge
    
    可以将其粘贴到https://j2live.ttl255.com中,并使用变量cond: true(或false) 来显示发生了什么
  • 我使用的是复印机,而不是直接使用 Jinja,如果这有任何区别的话

相关问题:

  • Jinja2 空白控制无法按预期与 IF 块配合使用- 似乎相关,但没有答案
templates
  • 1 个回答
  • 23 Views
Martin Hope
moudi
Asked: 2024-07-23 18:30:48 +0800 CST

如何在 C++17 中将 void 用于 std::conditional_t

  • 6

我尝试根据std::conditional_t类型定义类成员的 std::function 模板参数:

template <class T, size_t N = 1>
class MyClass {
    static_assert( (N > 0), "0 or less feature element isn't allowed");
public:
    typedef std::conditional_t<(N == 1), void, uint32_t> index_t;

private:
    std::function<T(index_t)> fRead;

public:
    template <typename U = T>
    std::enable_if_t<(N==1), U> getData()
    { return fRead(); }
    template <typename U = T>
    std::enable_if_t<(N>1), U> getData(uint32_t index)
    {
        if (index >= N) {
            throw std::out_of_range ("Index is out of range!");
        }
        return fRead(index);
    }
}

如果 N==1 并且如果 N>1,则类型fRead应该是。std::function<T(void)> fRead;std::function<T(uint32_t)> fRead;

不幸的是我收到了编译器错误:error: invalid parameter type ‘std::conditional<true, void, unsigned int>::type’ {aka ‘void’}。

fRead 成员用 lambda 函数初始化(该片段中未显示)。

我发现一些信息表明这void不是一个有效类型,不允许将其用作模板参数std::conditional_t。但不幸的是,我不知道如何解决这个问题。

templates
  • 1 个回答
  • 24 Views
Martin Hope
Nick
Asked: 2024-07-15 15:17:39 +0800 CST

以特定方式展开和折叠参数包

  • 6
#include <string>
#include <string_view>

template<typename... Args>
std::string_view concatenateBuffer(std::string &buffer, Args &&... args){
    static_assert((std::is_constructible_v<std::string_view, Args> && ...));

    buffer.clear();

    (buffer.append(std::forward<Args>(args)), ...);

    return buffer;
}


template<typename ...Ts>
std::string_view concat(std::string s, Ts ...ts){
    return concatenateBuffer(s , (("," , ts) , ...) );
}

#include <iostream>

int main(){
    std::string b;

    std::cout << concat(b, "a") << '\n';
    std::cout << concat(b, "a", "b") << '\n';
}

我有函数concatenateBuffer,我在这里展示的版本是简化的,但它的作用是将“字符串”(char *,string_view,string)附加到buffer。

我想做另一个concat类似于 php 函数 implode 的函数,例如在“字符串”之间放置分隔符“,”。

例如如果你调用:

    concat(b, "a")           ===> "a"
    concat(b, "a", "b")      ===> "a,b"
    concat(b, "a", "b", "c") ===> "a,b,c"

可以使用折叠参数包来完成吗?

templates
  • 1 个回答
  • 18 Views
Martin Hope
Thomas
Asked: 2024-04-16 22:45:38 +0800 CST

Rust:使用泛型专业化将枚举强制转换为自身

  • 5

我正在使用泛型专业化在某些枚举数据结构上具有自定义编译时类型:

pub trait MyEnumState{}

// All state are Zero Sized Type
pub struct State1; impl MyEnumState for State1{};
pub struct State2; impl MyEnumState for State2{};

// Note : I don't know is there is a PhantomData<S> for an enum
pub enum MyEnum<S: MyEnumState> {
    A,
    B,
    C(i32), // Can also have some data
    // ... long enum
}

现在我希望能够对它们进行转换:相同的值,不同的类型

// How to avoid this mess ???
impl MyEnum<State1> {
    pub fn to_state2(self) -> MyEnum<State2> {
        match self {
            MyEnum::A => MyEnum::A,
            MyEnum::B => MyEnum::B,
            MyEnum::C(v) => MyEnum::C(v),
        }
    }
}

// I can proably make a generic function
// ```
// fn cast
//     <StateBegin : MyEnumState, StateEnd : MyEnumState>
// (val MyEnum<StateBegin>) -> MyEnum<StateEnd> { ... }
// ```
// to avoid repetition but I still have at least 1 giant match to implement
impl MyEnum<State2> { ... }



impl<S : MyEnumState> MyEnum<S> 
{
   pub fn to_state<NewState : MyEnumState>(self) ->  MyEnum<NewState> 
   {
      // how ?!
   }
}

这只是一个简单的例子,目标是有0 个匹配语句以避免匹配所有现有的枚举变体。

templates
  • 1 个回答
  • 37 Views
Martin Hope
Aracthor
Asked: 2023-12-02 21:12:43 +0800 CST

我可以为泛型类型实现泛型 From<> 特征,以用于除自身以外的任何其他实现吗?

  • 5

我制作了一个通用的 Vector 结构,与不同的 T 类型一起使用:

struct Vector<T> {
    data: [T; 3],
}

Eq我已经为数学操作数( 、Index、 ...)实现了一些通用特征std::ops::Add,并且效果很好。

但现在,我正在努力实现一个From特征,以便我可以轻松地将向量转换为向量。

impl<T, U> From<Vector<U>> for Vector<T> {
    fn from(item: Vector<U>) -> Self {
        // [...]
    }
}

无论此from函数的实现如何,我都会收到以下错误:

error[E0119]: conflicting implementations of trait `From<Vector<_>>` for type `Vector<_>`
 --> <source>:5:1
  |
5 | impl<T, U> From<Vector<U>> for Vector<T> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: conflicting implementation in crate `core`:
          - impl<T> From<T> for T;

如果我理解正确的话,那是因为默认情况下,对于任何类型,From<Vector<T>> for Vector<T>都已经声明了。T如果和是相同的类型,我的实现会与之冲突U。

那么有没有一种方法可以将我的实现用于任何不同的类型T和U,但不能将其用于相同的类型T和U?

templates
  • 1 个回答
  • 24 Views
Martin Hope
Nate Ackerman
Asked: 2023-11-27 14:44:55 +0800 CST

为什么我调用 nim 模板不是简单地扩展模板代码?

  • 5

在 Nim 中工作时,我对模板的直觉是,在编译时,它们只是简单地扩展到代码中(通过适当的替换)。但是下面的代码:

type
    New_Type = ref object of RootObj

template Template_Procedure(T: untyped, vProc: bool = true) = 

    proc ProcedureA(self:var T, vInt: var int): int 

    when vProc == true:
        proc ProcedureA(self:var T, vInt: var int): int =
            var tReturn = vInt * vInt 
            return tReturn

    proc ProcedureB(self: var T, vInt: var int): int = 
        var tI = ProcedureA(self, vInt)
        return 2 * tI 

Template_Procedure(New_Type, vProc = false)

proc ProcedureA(self:var New_Type, vInt: var int): int =
    var tReturn = vInt * vInt * vInt
    return tReturn

var tNew = new(New_Type)
var tInt = 5
echo $ProcedureB(tNew, tInt)    

给出错误:

test3.nim(9, 10) Error: implementation of 'test3.ProcedureA(self`gensym0: var New_Type, vInt`gensym0: var int)' expected

然而如果我打电话

Template_Procedure(New_Type, vProc = true)

那么就没有错误了。

相反,如果我手动将模板的文本替换为调用它的位置,则会发生相反的情况。即,如果我将 vProc 替换为 false,则代码将编译并收到错误

Error: redefinition of 'ProcedureA'; previous declaration

如果我用 true 代替 vProc。

有人可以向我解释我对模板的直觉在哪里不正确吗?(或给我适当的参考资料)

另外,有没有一种方法可以编写在编译时简单扩展的代码?

具体来说,我希望能够调用 Template_Procedure(X, vProc = false),其中 X 是一种类型,然后,对于适当的类型 X,手动编写特定的

ProcedureA(self: var X, vInt var int): int

程序。对于其他X,只需调用Template_Procedure(X),而不必手动定义ProcedureA。

templates
  • 1 个回答
  • 38 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve